Microsoft KB Archive/137343

= INFO: VB Automation of Visual C++ Server Using OBJ1.OBJ2.prop Syntax =

Article ID: 137343

Article Last Modified on 11/21/2006

-

APPLIES TO

 Microsoft Foundation Class Library 4.2, when used with:  Microsoft Visual C++ 1.5 Professional Edition

 Microsoft Visual C++ 1.51

 Microsoft Visual C++ 1.52 Professional Edition

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

 Microsoft Visual C++ 2.1</li></ul>

 Microsoft Visual C++ 2.2</li></ul>

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

 Microsoft Visual C++ 4.1 Subscription</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q137343

<div class="summary_section">

SUMMARY
It is often necessary to access properties within nested objects exposed by OLE Automation. The Visual Basic syntax is: OBJ1.OBJ2.Property This article demonstrates the creation of a simple OLE Automation server with Visual C++, accessible from Visual Basic, that exposes such an object.

<div class="moreinformation_section">

MORE INFORMATION
The following steps demonstrate how to create a Visual C++ OLE Automation server that allows Visual Basic to use the OBJ1.OBJ2.Property syntax.

Steps to Create the Visual C++ OLE Automation Server
<ol> Create an AppWizard-generated project called AutoServ with OLE Automation enabled.</li> Once the project has been generated, start ClassWizard.</li> Click the OLE Automation tab.</li>  Click the Add Class button, enter the following values, and then click Create Class: <pre class="fixed_text">  Class Name:    nested Class Type:   CCmdTarget Check:        OLE Automation </li>  Click the ClassWizard's OLE Automation tab. Set the Class Name to nested, click the Add Property button, enter the following values, and then click OK: <pre class="fixed_text">  External Name: Value Type:         long </li>  Change the Class Name in ClassWizard to CAutoServDoc. If you are prompted to save changes, click Yes. Then click the Add Method button, enter the following values, and click OK: <pre class="fixed_text">  External Name: Nested Return Type:  LPDISPATCH </li> Click OK to accept the additions created by ClassWizard.</li>  Open the project's AutoServDoc.h file, and add the following line to the beginning of the file: #include "nested.h"                           </li> <li>To the same file, add a public member variable m_nested of type nested. A pointer mechanism could have been used to maintain the nested class; however, for this example, the chosen method will automatically create and destroy the nested object within the Documents constructor and destructor respectively.</li> <li>Open the project's nested.h file, and modify the class so that the constructor and destructor are public methods.</li> <li> Open the projects AutoServDoc.cpp file, and modify the Nested Method as follows: LPDISPATCH CAutoServDoc::Nested {      //TODO: Add your dispatch handler code here return m_nested.GetIDispatch(TRUE); }                           </li> <li>Build the project, and then run AutoServ.exe to register the server.</li></ol>

Steps to Test the Server in Visual Basic
<ol> <li>Start a new project in Visual Basic that will be used to test the OLE Automation server.</li> <li>On the View menu, click Code.</li> <li>In the Object combo box, select (general).</li> <li> Enter the following code: Dim Server As object </li> <li> Select Form in the Object combo box. Modify the Sub procedure as follows: Sub Form_Load Set Server = CreateObject("autoserv.document") Server.Nested.Value = 10 x = Server.Nested.Value End Sub </li> <li>Add x and Server.Nested.Value to the Visual Basic watch window, so that you can observe the changes while stepping into the Visual Basic program.</li></ol>

Additional query words: 1.50 1.51 1.52 2.00 2.10 2.20 2.50 2.51 2.52 3.00 3.10 3.20 4.00 4.10 vc vb client controller

Keywords: kbautomation kbcode kbinfo KB137343

-

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

© Microsoft Corporation. All rights reserved.