HOWTO: Provide Type Information From an MFC Automation Server
ID: Q185720
|
The information in this article applies to:
-
The Microsoft Foundation Classes (MFC), included with:
-
Microsoft Visual C++, 32-bit Editions, versions 4.0, 4.1, 4.2, 5.0, 6.0
SUMMARY
This article shows how to provide access to type information from an MFC
automation server at run time. MFC automation servers by default return
E_NOTIMPL for IDispatch::GetTypeInfo().
MORE INFORMATION
The automation object in the following steps refers to a CCmdTarget derived
object with automation enabled.
Step-by-Step Example
- Place the DECLARE_OLETYPELIB macro in the automation object's header
file within the class definition.
- Place the IMPLEMENT_OLETYPELIB macro in the automation object's
implementation file at global scope.
- Override CCmdTarget::GetDispatchIID() in your derived class, and then
return the IID of the primary dispatch interface.
SAMPLE CODE:
// In the header file for the automation object, say CmyAutoObject.
virtual BOOL GetDispatchIID(IID* pIID);
// In the implementation file for CmyAutoObject.
BOOL CMyAutoObject::GetDispatchIID(IID* pIID)
{
*pIID = IID_IMyAutoObject;
return TRUE;
}
- Call EnableTypeLib(), in the constructor for the automation object.
Make sure that the type library is registered using AfxOleRegisterTypeLib()
or RegisterTypeLib(), or that the type library is available as a resource
in the .dll or .exe file. For more information on how to add the type
library as a resource, please see the following article in the Microsoft
Knowledge Base:
Q122285 HOWTO: Add Type Libraries as Resources to .dll and .exe Files
(c) Microsoft Corporation 1998, All Rights Reserved. Contributions by
Jaganathan Thangavelu, Microsoft Corporation
Additional query words:
0x80004001 [ASCII 150] 2147500033
Keywords : kbole kbMFC kbVC400 kbVC410 kbVC420 kbVC500 kbVC600
Version : WINNT:4.0,4.1,4.2,5.0,6.0
Platform : winnt
Issue type : kbhowto
|