CreateObjrefMoniker function (objbase.h)

Creates an OBJREF moniker based on a pointer to an object.


HRESULT CreateObjrefMoniker(
  [in, optional] LPUNKNOWN punk,
  [out]          LPMONIKER *ppmk


[in, optional] punk

A pointer to the IUnknown interface on the object that the moniker is to represent.

[out] ppmk

Address of a pointer to the IMoniker interface on the OBJREF moniker that was created.

Return value

This function can return the standard return values E_OUTOFMEMORY, E_UNEXPECTED, and S_OK.


Clients use OBJREF monikers to obtain a marshaled pointer to a running object in the servers address space.

The server typically calls CreateObjrefMoniker to create an OBJREF moniker and then calls IMoniker::GetDisplayName, and finally releases the moniker. The display name for an OBJREF moniker is of the form:


Where nnnnnnnn is an arbitrarily long base-64 encoding that encapsulates the computer location, process endpoint, and interface pointer ID (IPID) of the running object

The display name can then be transferred to the client as text. For example, the display name can reside on an HTML page that the client downloads.

The client can pass the display name to MkParseDisplayName, which creates an OBJREF moniker based on the display name. A call to the monikers IMoniker::BindToObject method then obtains a marshaled pointer to the running instance on the server.

For example, a server-side COM component contained in an Active Server Page can create an OBJREF moniker, obtain its display name, and write the display name to the HTML output that is sent to the client browser. A script that runs on the client side can use the display name to get access to the running object itself. A client-side Visual Basic script, for instance, could store the display name in a variable called strMyName and include this line:

objMyInstance = GetObject(strMyName)

The script engine internally makes the calls to MkParseDisplayName and IMoniker::BindToObject, and the script can then use objMyInstance to refer directly to the running object.


Requirement Value
Minimum supported client Windows 2000 Professional [desktop apps | UWP apps]
Minimum supported server Windows 2000 Server [desktop apps | UWP apps]
Target Platform Windows
Header objbase.h
Library Ole32.lib
DLL Ole32.dll
API set ext-ms-win-com-ole32-l1-1-5 (introduced in Windows 10, version 10.0.15063)

See also