display | more...
HRESULT CoMarshalInterThreadInterfaceInStream(REFIID riid, LPUNKNOWN pUnk, LPSTREAM *ppStm);

Quite possibly the longest function name in the Win32 SDK. The purpose of CoMarshalInterThreadInterfaceInStream is to easily and reliably marshal COM interface pointers between threads. The stream returned in ppStm is guaranteed to behave correctly when a client running in the receiving thread attempts to unmarshal the pointer. The client can then call the CoGetInterfaceAndReleaseStream to unmarshal the interface pointer and release the stream object.

Not using this function is probably one of the greatest pitfalls in multithreaded COM programming. In my experience, if you don't use it, you're asking for trouble. It will create a scenario where some of your objects work fine between threads, and others just don't. COM will do things like mysteriously, and without warning, drop your method calls.

Log in or register to write something here or to contact authors.