BindMoniker

Locates an object by means of its moniker, activates the object if it is inactive, and retrieves a pointer to the specified interface on that object.

HRESULT BindMoniker(
  LPMONIKER pmk,     //Pointer to the object's moniker
  DWORD grfOpt,      //Reserved
  REFIID iidResult,  //Interface identifier
  LPVOID FAR *ppvResult
                     //Address of output variable that receives the 
                     // interface pointer requested in iidResult
);
 

Parameters

pmk
[in] Pointer to the object's moniker.
grfOpt
[in] Reserved for future use; must be zero.
iidResult
[in] Interface identifier to be used to communicate with the object.
ppvResult
[out] Address of pointer variable that receives the interface pointer requested in iidResult. Upon successful return, *ppvResult contains the requested interface pointer. If an error occurs, *ppvResult is NULL. If the call is successful, the caller is responsible for releasing the pointer with a call to the object's IUnknown::Release.

Return Values

S_OK
The object was located and activated, if necessary, and that a pointer to the requested interface was returned.
MK_E_NOOBJECT
The object that the moniker object identified could not be found.

This function can also return any of the error values returned by the IMoniker::BindToObject method.

Remarks

BindMoniker is a helper function supplied as a convenient way for a client that has the moniker of an object to obtain a pointer to one of its interfaces. The BindMoniker function packages the following calls:

CreateBindCtx(0, &pbc); 
pmk->BindToObject(pbc, NULL, riid, ppvObj); 
 

CreateBindCtx creates a bind context object that supports the system implementation of IBindContext. The pmk parameter is actually a pointer to the IMoniker implementation on a moniker object. This implementation's BindToObject method supplies the pointer to the requested interface pointer.

If you have several monikers to bind in quick succession, and if you know that those monikers will activate the same object, it may be more efficient to call the IMoniker::BindToObject method directly, which allows you to use the same bind context object for all the monikers. See the IBindCtx interface for more information.

Container applications that allow their documents to contain linked objects are a special client that generally does not make direct calls to IMoniker methods. Instead, the client manipulates the linked objects through the IOleLink interface. The default handler implements this interface and calls the appropriate IMoniker methods as needed.

QuickInfo

  Windows NT: Use version 3.1 or later.
  Windows: Use Windows 95 or later.
  Windows CE: Unsupported.
  Header: Declared in objbase.h.
  Import Library: Included as a resource in ole32.dll.

See Also

CreateBindCtx, IMoniker::BindToObject