Information: VB Automation Of Visual C Server Using Obj1.obj2.prop Syntax Article ID: 137343 Bid Comments: December 1, 2003 Correlated Version: 1.0 This article was previously published in Q137343
Source page (English): http://support.microsoft.com/default.aspx? Scid = kb; EN-US; 137343
Translation: huyoo, beard from: http://blog.9cbs.net/huyoo [- Reprinted please do not delete this information -]
Directory summary more information
Summary Programming Nested Nested Objects in Ole Automation Server. Visual Basic Syntax is: Obj1.obj2.property This article demonstrates how to create a simple Ole Automation server in the Viusal C environment, then in Visual Basic Call the nested object access attribute of the server.
MORE INFORMATION The following steps demonstrate how to create an OLE Automation server in VC , which allows syntax access to Obj1.obj2.property in Visual Basic.
Steps to create an OLE Automation server in VC : 0 Use AppWizard to create an engineering of AutoServ, single document structure, select the Automation this item. 2. AppWizard creates completion, check ClassWizard. 3. Click to select the Automation tab .4. Click the Add Class button, enter the following value, create the following class: Class Name: Nested Class Type: CCMDTARGET Select Automation 5. Click ClassWizard's Automation tab. Select Class Name as Nested, click Add Property button, enter the following value, then click OK: EXTERNAL: VALUE TYPE: Long 6. Change the class name (classname) in ClassWizard to Cautoservdoc. At this time, it is possible to popup whether the change is saved, click Yes. Then click the Add Method button to enter the following value, click OK. External Name: NESTED RETURN TYPE: LPDISPATCH 7. Point OK to accept these parts added by ClassWizard.
8. Open Project's autoservdoc.h file, add this line below: #include "nested.h" 9. In the same file, add a public member variable m_NNESTED, type NESTED An committee will be used to maintain this NESTED class; however, in this case, the selected method will separately follow the documentation and sectors of Documents, and the auto-constructed object NESTED (it turns a document) Subclass)
10. Open Project's NESTED.H file and modify the constructor of this NESTED class and the sector of the destructor for the public for the Document call.
11. Open Project's 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);} 12. Compile Engineering, then run AutoServ.exe to register this server to the registry. In Visual Basic Test this server program.
1. Start a new project in Visual Basic to test this Ole Automation server. 2. Switch to the code editing mode. 3. In the composite drop-down box selected by the object, choose General .4. Enter the following code: DIM Server As Object 5. In the composite dropboard selected by the object, select Form. Modify the Sub process as follows: SUB FORM_LOAD () SET Server = CreateObject ("AutoServ.Document") debug.print server.nested.value 'I added Server .NESTED.VALUE = 10 x = server.nested.value 'I added debug.print x end sub 6. Add X and Server.Nested.Value to the Visual Basic Watch window, so when you are step-by-step debugging, you will The changes in their values can be observed.
-------------------------------------------------- -------- I have tested the code, compiled in the environment of VC6.0, successfully achieved in VB6.0.
The sixth step is actually no longer needed.
Reference:
GUI doctor and COM automation, the first part http://www.microsoft.com/china/msdn/library/archives/techvoice/10.asp
Automation object http://blog.9cbs.net/wingforward/archive/2005/01/12/250539.aspx
Automation In C Builder http://blog.9cbs.net/kingcaiyao/archive/2003/02/24/15200.aspx