How to use VC ++ and Visual FoxPro for ActiveX Data Communication

zhaozj2021-02-08  312

How to use VC and Visual FoxPro to make ActiveX Data Communication, Musicin Sun Qiang, this article describes how to use automatic server ACTIVE Automation to communicate with Visual FoxPro in VC . Through the automatic server, the exchange of various data types is solved. Key words VC , Visual FoxPro, ActiveX Automation, Data Communication In progress, how to exchange and communications between different programming tools, requires constant 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 Enddefine 2. 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. Turn off Visual FoxPro, select the menu item "file-new" in VC , select the "MFC AppWizard (EXE)" option in "Projects", then generate "Dialog Based" project according to the default mode (this example For mytest).

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.

转载请注明原文地址:https://www.9cbs.com/read-1517.html

New Post(0)