During software development, data exchange and communication between different programming tools require continuous exploration and summary. In the process of developing mechanical CAD simulation software, we encountered problems in VIXPRO in VC . After many experiments, we solved this problem by using the ActiveX Automation method. Automatic server, previously referred to as Ole Automation, later called ActiveX Ole Automation, is the code written by other programs. Other programs are not a user code that directly calls the auto server in a DLL isolated approach. This is more difficult to understand is: Automatic server user code reveals attributes (variables) and methods (functions) to other applications. Hereinafter, data is transmitted as an example, how to use ActiveX Automation between VC and Visual FoxPro, and the programming tool is VC 5.0 and Visual FoxPro 5.0 . One. Create auto server 1 in Visual FoxPro. Define a server class in Visual FoxPro (in this case) First, create a new project in a directory, select the code bar in the Engineer, create a new program (such as MyServer.prg) in the same directory, and in this program Define server classes in the file. * File name: myserver.prg define class cdata as custom olepublic * For VC , Para1 is intellectual, para2 is Double PARA1 = 123 Para2 = 123.123 procedure changeata this.pa1 = this.paa1 * 2 this.para2 = this . Para2 * 2 Return EndProc Enddefine2. Connected the above program to the executable program (such as MyServer.exe) selected program MyServer, click the "Contact" button, select the "Connectable Executable" option and press OK to generate an executable program. Two. Test 1 in VC 1. Close Visual FoxPro, select the menu item "file-new" in VC , and then
Select "The MFC AppWizard (EXE" option in "Projects", then generate "Dialog Based" project (this example is Mytest) by default. 2. The initInstance () function of the app class in MyTest.cpp is added to the OLE Enable Bool CMYTESTAPP :: InitInstance () {bool Oleenable = Afxoleinit (); if (! Oleenable) Return False; ......} 3. "Add class-from a type library" in "Automation" in ClassWizard. Find the TLB file (such as MyServer.tlb) under the Visual FoxPro project currently created and select "Open" and select the "Open" button, you will have a CDATA class from the lib. Click OK. The button confirmed that the file MyServer.cpp and MyServer.h related to the CDATA class will be added automatically. In ClassView, you can view the function of CDATA classes, such as getPara1 (), setPara1 (), and ChangeData (), etc.. Here you should pay attention to the case of CDATA and function name ChangeData (), please refer to the specific header file MyServer.h. 4. In the header of the header file mytestdlg.h of the dialog class (CMYTESTDLG), the header file MyServer.h of the CDATA class is included. The instance M_Data of the CDATA class is then defined as a member variable of the dialog box class. // MyTestDlg.h: header file #include "myserver.h" ...... class CMyTestDlg: public CDialog {// Construction public: CMyTestDlg (CWnd * pParent = NULL); // standard constructor private: CDATA m_data; // defined CDATA Instance m_data ...} ... 5. Add m_data.createdispatch ("MyServer.cdata) in the dialog box (" MyServer.cdata) ("MyServer.cdata); Test the Auto Server by clicking this button.