Dynamic data exchange

Introduction

On Windows, OS / 2, and other operating systems (with third-party development tools), dynamic data exchange (DDE) allows data Shared or communicating between the program. For example, when you change a table in your database program, or when the data item in the electronic tab is, the table or data item also needs to make a corresponding change in the other software you may use. DDE is inter-process communication with shared memory as a public switching area and provides an application a protocol or command set, and a message format. DDE uses the client / server model, in which the application processes the data on the client, while the application provides data on the server.

Working principle

DDE Working principle is:

Two simultaneous running programs are exchanged in DDE mode when switching data, once The client and server establish a connection relationship, then the customer will be notified immediately after the data in the server changes. The data connection channel established by the DDE mode is two-way, that is, the customer can not only read the data in the server, but also modify it.

DDE and clipboard support both standard data formats (such as text, dot matrix, etc.), but also support customized data formats. However, their data transfer mechanisms are different, and a clear difference is that the clipboard operation is almost always used as a disposable response to the user's designated operation, such as selecting paste commands from the menu. Although DDE can be started by the user, it continues to play, generally does not have to further intervene.

, for example:

Party A applies a global memory, then put the memory pointer PostMessage to Party B, Party B is accessed to access the global memory according to the pointer received. There are a few API functions to do this, and you check the function of DDE head in MSDN. Because it is the technology that has been eliminated, even MFC did not package him. It is difficult to ensure that it will also appear in the future Windows API.

Content

DDE dialogue is contemplated by three identifier.

1, the application name: The name of the two parties of the DDE dialog. The name of the commercial application is given in the product documentation. The program name "Configuring King" running system is "view"; Microsoft Excel's application name is "Excel"; Visual Basic program uses the name of the executable.

2, topic: Domain discussed. For the "Configuration King", the subject specified as "tagname"; Excel's theme name is the name of the spreadsheet, such as Sheetl, Sheet2, ...; Visual Basic program, the topic of the Visual Basic program is specified by the form of the LINKTOPIC property value. .

3, item: This is a specific data object discussed. In the data dictionary of "Configuring King", engineers define the I / O variables while also defining the project name. The item in Excel is a unit, such as RLC2 (RLC2 represents the first line, the second column unit). For the Visual Basic program, the project is a specific text box, the name of the label, or picture box.

Exchange method

(1) Cold connection (COOLLINK): Data exchange is a disposable data transmission, the same as the clipboard. When the data in the server changes, the customer can read and write data from the server at any time;

Dynamic data exchange

(2) WarmLink: When the data in the server changes, it will notify the customer immediately after the data is changed. When the customer gets notified, the data is retrieved;

(3) Hot connection: When the data in the server changes, it will notify the customer immediately while the changed data is sent directly to the customer.

DDE client requests data to the DDE server program, it must first know the name of the server (ie DDService name), DDE theme name (Topics name), and know which project name requesting which data item (Items name). The DDService name should have uniqueness, otherwise it is easy to make confusion. Usually DDService is the server's program name, but not absolute, it is set by the program designer in the program, not by modifying the program name. The Topics name and Items name are also set by DDeService, and the service name of all servers is registered in the system. When a customer requests data to a server, the customer must report the server's service name and Topics name. Only when the service name, the Topics name is consistent with the names set by the server, the system communicates the client's request to the server.

When the service name is consistent with the Topics name, the server immediately determines whether the Items name is legal. If the requested Item name is the legal data item in the server, the server is established, and the server will notify the customer in time after the data is established. A server can have multiple Topics names, and the number of items names is not limited.

DDE exchange can occur between applications of different computers in a single or network. Developers can also define custom DDE data formats, and the special purpose IPC between applications, which have a more closely coupled communication requirements. Most Windows-based applications support DDE. However, DDE has a significant disadvantage that the communication efficiency is low, and when the traffic is large, the data refresh is slow, and the DDE is more practical when the data is less.

Writing Program

For the convenience of use, Microsoft provides the DDE Management library (DDEML). DDEML specializes in coordinating DDE communication, providing DDE applications with handle strings and data exchange services, eliminating problems caused by the Upper DDE protocols.

Applications developed using DDEML (Customer / Server) are better than the DDEML applications in terms of operational consistency or in terms of programming. Moreover, DDEML applications make it easy for developing DDE applications because DDEML (this is a DLL) works in the Work of the Office of the Office. After using DDEML, most sessions between customers and servers are not directly reached, but via DDEML, that is, using the Callback function to process DDE transactions, and early messaging is directly.

Before calling other DDEML functions, the client / server must call the DDeinitialize () function to get the instance identifier, register the DDECALLBACK function, and specify the transaction filtering for the Callback function. For the server, after using DDeinitialize (), call DDecreateStringHandle () to create a handle of the service name, Topics name, and Items name, and then register the server in the operating system by DDENAMESERVICE (). Based on these handles, customers can use the DDE service it provides.

In order to perform a DDE task, many DDEML functions require access to strings. For example: a customer must specify the service name and Topics name when calling the DDEConnect () function to request a session with the server. You can get a specific string handle by calling the DDecreateStringHandle () function. For example:

HSZHSZSERVNAME = DDECREATESTRINGHANDLE (iDinst, "myserver", cp_winansi);

hszroszsystopic = ddecreateStringHandle (iDinst, szddesys_topic, cp_winansi);

an application The DDE callback function receives multiple string handles in most DDE transactions. For example: During the XTYP_REQUEST transaction processing, a DDE server receives two string handles: an identifier Topics name string, another identifier Items name string. You can get the character string length corresponding to the string handle by calling the DdeQueryString () function, and replicates the string to the application defined buffer. For example:

dwordidinst;

dwordcb;

HSZHSZSERV;

pstrpszservname;

cb = DDEQUERYSTRING (iDinst , HSZSERV, (LPSTR) NULL, 0, CP_WINANSI) +1;

pszservname = (pstr) Localalloc (LPTR, (UINT) CB);

DdeQueryString (iDinst, HSZSERV, PSZSERVNAME, CB, CP_WINANSI;

According to Microsoft MSDN, the existing message DDE-based application is compatible with DDEML applications, that is, message-based DDE applications can be DDEML application dialogue and transactions. When using DDEML, you must include DDEML.h header files in the source file file, connect the user32.lib file, and ensure the correct system path of the DDEML.dll file.

Related Articles
TOP