IMarshal::GetUnmarshalClass  199ZBW2

Returns the CLSID that COM uses to locate the DLL containing the code for the corresponding proxy. COM loads this DLL to create an uninitialized instance of the proxy.

HRESULT GetUnmarshalClass(

    REFIID riid,

//Reference to the identifier of the interface to be marshaled

    void * pv,

//Interface pointer being marshaled

    DWORD dwDestContext,

//Destination process

    void * pvDestContext,

//Reserved for future use

    DWORD mshlflags,

//Reason for marshaling

    CLSID * pCid

//Pointer to CLSID of proxy

   );

 

 

Parameters

riid

[in] Reference to the identifier of the interface to be marshaled.

pv

[in] Pointer to the interface to be marshaled; can be NULL if the caller does not have a pointer to the desired interface.

dwDestContext

[in]  Destination context  where the specified interface is to be unmarshaled. Values for dwDestContext come from the enumeration MSHCTX3T9G8X5. Currently, unmarshaling can occur either in another apartment of the current process (MSHCTX_INPROC) or in another process on the same computer as the current process (MSHCTX_LOCAL).

pvDestContext

[in] Reserved for future use; must be NULL.

mshlflags

[in] Whether the data to be marshaled is to be transmitted back to the client process   the normal case   or written to a global table, where it can be retrieved by multiple clients. Valid values come from the MSHLFLAGS8DNAZK enumeration.

pCid

[out] Pointer to the CLSID to be used to create a proxy in the client process.

 

Return Value

Returns S_OK if successful; otherwise, S_FALSE.

Remarks

This method is called by whatever code in the server process may be responsible for marshaling a pointer to an interface on an object. This marshaling code is usually a stub generated by COM for one of several interfaces that can marshal a pointer to an interface implemented on an entirely different object. Examples include the IClassFactory3AWUS9 and IOleItemContainer1MMKGIR interfaces. For purposes of this discussion, the code responsible for marshaling a pointer is called the  marshaling stub. 

To create a proxy for an object, COM requires two pieces of information from the original object: the amount of data to be written to the marshaling stream and the proxy s CLSID.

The marshaling stub obtains these two pieces of information with successive calls to CoGetMarshalSizeMax1R8C3A and CoMarshalInterfaceKHF9NR.

Note to Callers

The marshaling stub calls the object s implementation of this method to obtain the CLSID to be used in creating an instance of the proxy. The client, upon receiving the CLSID, loads the DLL listed for it in the system registry.

You do not explicitly call this method if you are:

    Implementing existing COM interfaces, or

    Defining your own interfaces using the Microsoft Interface Definition Language (MIDL).

 

In both cases, the stub automatically makes the call. See  Writing a Custom Interface1HPLHTF

If you are not using MIDL to define your own interface, your stub must call this method, either directly or indirectly, to get the CLSID that the client-side COM Library needs to create a proxy for the object implementing the interface.

If the caller has a pointer to the interface to be marshaled, it should, as a matter of efficiency, use the pv parameter to pass that pointer. In this way, an implementation that may use such a pointer to determine the appropriate CLSID for the proxy does not have to call IUnknown::QueryInterface2Y54585 on itself. If a caller does not have a pointer to the interface to be marshaled, it can pass NULL.

Notes to Implementers

COM calls GetUnmarshalClass to obtain the CLSID to be used for creating a proxy in the client process. The CLSID to be used for a proxy is normally not that of the original object (see  Notes to Implementers  for the exception), but one you will have generated (using the GUIDGEN.EXE tool supplied with the Win32 SDK) specifically for your proxy object.

Implement this method for each object that provides marshaling for one or more of its interfaces. The code responsible for marshaling the object writes the CLSID, along with the marshaling data, to a stream; COM extracts the CLSID and data from the stream on the receiving side.

If your proxy implementation consists simply of copying the entire original object into the client process, thereby eliminating the need to forward calls to the original object, the CLSID returned would be the same as that of the original object. This strategy, of course, is advisable only for objects that are not expected to change.

If the pv parameter is NULL and your implementation needs an interface pointer, it can call IUnknown::QueryInterface2Y54585 on the current object to get it. The pv parameter exists merely to improve efficiency.

To ensure that your implementation of GetUnmarshalClass continues to work properly as new destination contexts are supported in the future, delegate marshaling to COM s default implementation for all dwDestContext values that your implementation does not handle. To delegate marshaling to COM s default implementation, call the CoGetStandardMarshal._04TA function.