共用方式為


ATL and the Free Threaded Marshaler

 

The latest version of this topic can be found at ATL and the Free Threaded Marshaler.

The ATL Simple Object Wizard's Attributes page provides an option that allows your class to aggregate the free threaded marshaler (FTM).

The wizard generates code to create an instance of the free threaded marshaler in FinalConstruct and release that instance in FinalRelease. A COM_INTERFACE_ENTRY_AGGREGATE macro is automatically added to the COM map to ensure that QueryInterface requests for IMarshal are handled by the free threaded marshaler.

The free threaded marshaler allows direct access to interfaces on your object from any thread in the same process, speeding up cross-apartment calls. This option is intended for classes that use the Both threading model.

When using this option, classes must take responsibility for the thread-safety of their data. In addition, objects that aggregate the free threaded marshaler and need to use interface pointers obtained from other objects must take extra steps to ensure that the interfaces are correctly marshaled. Typically this involves storing the interface pointers in the global interface table (GIT) and getting the pointer from the GIT each time it is used. ATL provides the class CComGITPtr to help you use interface pointers stored in the GIT.

See Also

Concepts
CoCreateFreeThreadedMarshaler
IMarshal
When to Use the Global Interface Table
In-Process Server Threading Issues