Microsoft KB Archive/198422

= PRB: Unable to Display MFC Automation Objects in Watch Window =

Article ID: 198422

Article Last Modified on 5/12/2003

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Visual C++ 5.0 Enterprise Edition
 * Microsoft Visual C++ 6.0 Enterprise Edition

-



This article was previously published under Q198422



SYMPTOMS
If you access an automation server with a dual interface created in Visual C++ using the Microsoft Foundation Classes (MFC) from a Visual Basic application, you cannot display the properties of the automation objects in the Local or Watch window when you debug your Visual Basic program.



CAUSE
The default return value of IDispatch::GetTypeInfo implemented by MFC automation servers is E_NOTIMPL.



RESOLUTION
To resolve the problem, add code in the MFC project to provide access to type information from the MFC automation server.



STATUS
This behavior is by design.



Steps to Reproduce Behavior
Create a MFC automation server with dual interface:


 * 1) The Microsoft Developer Network CD that ships with Visual C++ contains the sample ACDUAL. Copy it to a directory on your hard drive.
 * 2) Open the ACDUAL sample in Visual C++.
 * 3) Build the project and run it. The automation server will be registered automatically.

Create a Visual Basic client program:

 Create a Visual Basic Standard EXE project. Form1 is created by default. From the Project menu, choose References and add a reference to ACDual. Add a command button to Form1. Command1 is created by default.  Paste the following code into the General Declarations section of Form1: Option Explicit Private Sub Command1_Click Dim obj As ACDual.Document Dim strtext

Set obj = CreateObject("ACDual.Document") obj.ShowWindow strtext = obj.Text End Sub  Set up a breakpoint on the line "strtext = obj.Text".</li> Run the program. When Form1 displays, click the Command1 button. The program stops on the line "strtext = obj.Text".</li> From the View menu, choose Locals Window to display the Locals window. Click the "+" sign that appears to the left of the "obj" expression.

If you are using Visual Basic 5.0, you receive the following error message:

This functionality is not yet implemented.

If you are using Visual Basic 6.0, the "obj" variable expands, but none of the properties of "Document" are listed.</li></ol>

NOTE: The same behavior occurs when using the Watch Window.

Step to Resolve the Problem
<ol> Open the MFC project ACDUAL in Visual C++.</li>  Open the AClikDoc.h file.

Add the following line to the class definition after the line "DECLARE_DYNCREATE(CAutoClickDoc)": DECLARE_OLETYPELIB(CAutoClickDoc) Add the following line after the "DECLARE_INTERFACE_MAP" statement in the class CAutoClickDoc definition: virtual BOOL GetDispatchIID(IID* pIID); </li>  Open the AClikDoc.cpp file.

Near the top of the file add the following code after the "IMPLEMENT_DYNCREATE(CAutoClickDoc, CDocument)" statement: //Replace the following with the GUID for your own typelib. const GUID CDECL BASED_CODE _tlid = { 0x4B115284, 0x32F0, 0x11cf, { 0xAC, 0x85, 0x44, 0x45, 0x53, 0x54, 0x0, 0x0} }; const WORD _wVerMajor = 1; const WORD _wVerMinor = 0;

IMPLEMENT_OLETYPELIB(CAutoClickDoc, _tlid, _wVerMajor, _wVerMinor) Add the following line after the "//{{AFX_DISPATCH_MAP(CAutoClickDoc)" statement: DISP_PROPERTY(CAutoClickDoc, "text", m_str, VT_BSTR) Add the following line after the "EnableAutomation;" statement in CAutoClickDoc::CAutoClickDoc: EnableTypeLib; Near the end of the file, add the following code before the "IMPLEMENT_DUAL_ERRORINFO(CAutoClickDoc, IID_IDualAClick)" statement: BOOL CAutoClickDoc::GetDispatchIID(IID* pIID) {        *pIID = IID_IDualAClick;

return TRUE; }                       </li> Rebuild the project and exit Visual C++.</li> Open the Visual Basic client program you created earlier, set the same breakpoint and run the program. When the program stops on the line "strtext = obj.Text", go to the Locals window, and click the "+" sign that appears to the left of the obj symbol in the expression column. The "obj" variable expands and displays all of the properties and their values for "Document" object.</li></ol>

Additional Information
If you develop your own MFC automation server with a dual interface, you need to include the following in your project:


 * For each property of your automation server, you must implement two sets of functions. One is for the dual interface implementation and the other is for the dispinterface implementation. For example, in the "x" property of the class CAutoClickDoc in then ACDUAL sample code, there are put_x and get_x functions for the dual interface implementation as well as GetX and SetX functions for the dispinterface implementation. -and-


 * Use AfxOleRegisterTypeLib to register your type library in your code.

Additional query words: kbDSupport

Keywords: kbautomation kbprb kbcode KB198422

-

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

© Microsoft Corporation. All rights reserved.