Partager via


COM_INTERFACE_ENTRY Macros

These macros enter an object's interfaces into its COM map so that they can be accessed by QueryInterface. The order of entries in the COM map is the order interfaces will be checked for a matching IID during QueryInterface.

Each object that wants to expose its interfaces via QueryInterface must have its own COM map. The COM map starts with the macro BEGIN_COM_MAP. Interface entries are added with one or more of the COM_INTERFACE_ENTRY macros, and the map is completed with the END_COM_MAP macro. For example:

BEGIN_COM_MAP(CMyObject)
   COM_INTERFACE_ENTRY(IMyObject)
   COM_INTERFACE_ENTRY(IDispatch)
END_COM_MAP()

Note that the first entry in the COM map must be an interface on the object containing the COM map. Thus, you cannot start your COM map entries with COM_INTERFACE_ENTRY_CHAIN, which causes the COM map of a different object to be searched at the point where COM_INTERFACE_ENTRY_CHAIN(COtherObject) appears in your object's COM map. If you want to search the COM map of another object first, add an interface entry for IUnknown to your COM map, then chain the other object's COM map. For example:

BEGIN_COM_MAP(CThisObject)
   COM_INTERFACE_ENTRY(IUnknown)
   COM_INTERFACE_ENTRY_CHAIN(CBase)
END_COM_MAP()

Warning

As of version 3.0, ATL uses the compiler keyword __uuidof( class ) to obtain the corresponding IID for a given class. Because of changes in the COM_INTERFACE_ENTRY macros effective in version 3.0, now you simply include the header for the interface to use, instead of also linking to a library that defines the matching IIDs for that interface. This change can cause problems if the header was previously generated by an older version of MIDL, or if it was hand-coded and not marked appropriately. If the declaration for the interface in the header has not been marked with an associated __declspec( uuid ), then any attempt to use the __uuidof keyword for that interface will fail. You can revert to the older (ATL 2.x) COM_INTERFACE_ENTRY macros by defining _ATL_NO_UUIDOF in your build settings to work around any problems with this new behavior.

COM Map Entry Macros

The following are the available entry macros:

Requirements

Header: atlcom.h

See Also

Other Resources

COM Map Macros

ATL Macros