Automation In C ++ Builder

zhaozj2021-02-16  42

Automation: Automation server, based on CoM technology, it can be other application-driven components .ocx, or separate EXE files, there are three types: internal servers, local servers, process servers, whenever servers, it There must be at least one or more IDispatch interfaces for other applications, the automation server can have no interface (UI) .a. A server: it can't run alone, there is no separate process address space, accurately Run within the process of the automation controller, such servers include DLL, OCX.B. Local Server: Such servers have their own processes, but must run on one machine with the automation controller .c. Process server : Like the local server, it has its own process floor space, but it and the automation controller are not on the same machine, which is located in different machines with the automation controller. Automated server and DLL are: Automation Server due to programming Language independence, so it can only use limited data types, and DLL can use any data type in a specific locale. The IDispatch interface is the core of the automation server, and it is also a mechanism for the automation server. It is in different languages. The interface under the work, the so-called automation controller is the customer who uses the IDispatch interface to access the Automation server object, the specific access process must first create an Automation server object first, then get the idispatch interface pointer through the QueryInterface method in the iUnknown interface, IDispatch The interface traces the properties and methods in the server through the internal DISPIDS structure. Dispid is the unique identifier of each attribute and method in the server. After obtaining the DISPID of each attribute and method through the iDispACTH interface, it will pass it to the DISPIDS structure. However, this structure is valid at the runtime (which means they can only be accessed at the runtime, specifically, during the running controller accesses the structure through GetIDSOFNAME), so this kind of access is called the back binding. If You can access the structure during compilation, it is called the front binding. The dual interface belongs to the front binding. Dual interface (VTable Interface), also known as user-defined interface, but its implementation is made by VTABLE (virtual function table), So it is also called VTable Interface. Its access speed is compared to the iDispatch interface. The reason is that vTable can be seen as a virtual function list, which is the initial three entrances for storing three of the IUNKNOWN (base class) interface. The address of the function (Queryinterface, AddRef, Release), Then the address of the four functions of the IDispACTH interface, the other is stored in the address of each attribute and method, if the type library header file is included, the VTABLE can get any DISPIDS structure in the type library, and during compilation Just bind on the VTABLE shell (that is, tcomi ****) so that you can directly access the VTABLE interface to access the properties and methods in the server, avoid calling the getispatch's getIdsOfNames and Invoke methods, so it's access speed. In the IDispACTH interface, the following will write a simple server and client to make a demonstration, I only post the main part of the code: // server: Written in september, 2002stdmethodImpl t **** :: __fastcall getdata (bstr * slist) { Tstrings * plist = new tstringlist (); try {tstrings * plist = new tstringlist (); tQuery * query = new tQuery (null); query-> databasename = "all_ttmis"; query-> close (); query-> sql -> Clear (); query-> sql-> add ("SELECT * A0"); query-> open (); query-> first (); while (! Query-> eof) {plist-> add ( Query->

FieldbyName ("Specified Field") -> Asstring); Query-> Next ();} * slist = (wideString) (PLIST-> text) (); query-> close (); delete plist; delete query; } Catch (Exception & E) {if (plist) {delete plist;}} {delete query;} Return Error (E.MESSAGE.C_STR (), IID_IYOOOK;}

// Calling Atclient

// Method 1: IDispacth Interfacevoid __fastcall TForm1 :: Button1Click (TObject * Sender) {WideString S; IYourInterfaceDisp app; app.BindDefault (); app.GetData (& S); TStrings * pList = new TStringList (); pList-> Text = String (s); for (int i = 0; i count; i ) {memo1-> lines-> add (plist-> strings [i]);} app.unbind (); delete plist; }

// Method 2: VTable Interfacevoid __fastcall TForm1 :: Button2Click (TObject * Sender) {WideString S; TCOMIYourInterface app = CoYourInterface :: Create (); app-> GetData (& S); TStrings * pList = new TStringList (); pList- > Text = string (s); for (int i = 0; i count; i ) {memo1-> lines-> add (plist-> strings [i]);} delete plist;

The above is my understanding of COM, but also hope that COM heroes.

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

New Post(0)