Custom Marshaling

Generally, it is acceptable to use standard marshaling, but there are times when a more efficient custom marshaler is required. A good example of when you would want to use custom marshaling is when you are passing a value or when something is read-only and will never change. In these cases, there is no need to call the real object anymore since the proxy has stored its state. An object can implement custom marshaling by exposing an IMarshal interface. Listing 11.10 shows the definition of the IMarshal interface.

Code Listing 11.10. Definition of the IMarshal Interface
 interface IMarshal : IUnknown { HRESULT GetUnmarshalClass([in] REFIID riid, [in, unique] void * pv, [in] DWORD dwDestContext, [in, unique] void * pvDestContext, ...

Get COM+ Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.