Microsoft KB Archive/185720

= How to provide access to type information from an MFC automation server at run time =

Article ID: 185720

Article Last Modified on 11/21/2006

-

APPLIES TO

 Microsoft Foundation Class Library 4.2, when used with:  Microsoft Visual C++ 4.0 Standard Edition

 Microsoft Visual C++ 4.1 Subscription

 Microsoft Visual C++ 4.2 Enterprise Edition

 Microsoft Visual C++ 4.2 Professional Edition</li></ul>

 Microsoft Visual C++ 5.0 Enterprise Edition</li></ul>

 Microsoft Visual C++ 5.0 Professional Edition</li></ul>

 Microsoft Visual C++ 6.0 Enterprise Edition</li></ul>

 Microsoft Visual C++ 6.0 Professional Edition</li></ul>

 Microsoft Visual C++ 6.0 Standard Edition</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q185720

<div class="summary_section">

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.

<div class="moreinformation_section">

MORE INFORMATION
The automation object in the following steps refers to a CCmdTarget derived object with automation enabled.

Step-by-step example
<ol> Place the DECLARE_OLETYPELIB macro in the automation object's header file within the class definition.</li> Place the IMPLEMENT_OLETYPELIB macro in the automation object's implementation file at global scope.</li>  Override CCmdTarget::GetDispatchIID in your derived class, and then return the IID of the primary dispatch interface.

Sample code
virtual BOOL GetDispatchIID(IID* pIID);

// In the implementation file for CmyAutoObject. BOOL CMyAutoObject::GetDispatchIID(IID* pIID) {        *pIID = IID_IMyAutoObject; return TRUE; }                   </li> Call EnableTypeLib, in the constructor for the automation object.</li></ol>

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 about how to add the type library as a resource, click the following article number to view the article in the Microsoft Knowledge Base:

122285 How to 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: kbautomation kbhowto KB185720

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.