Implementation of Visual C + + process data communication between processes

Source: Internet
Author: User

In Windows systems, there is often a need to exchange and pass data between applications (processes), which is the solution to the communication problem between processes. In the original 16-bit windows3.x system, all Windows applications shared a single address, and any process was able to read and write data for that shared address space. With the advent of 32-bit operating systems such as Windwos98, WindowsNT, Windows2000, each process has its own address space, and a Windows process cannot access private data for another process, i.e. Although two processes can be addressed with pointers with the same value, they are read and written only to their respective data, thus reducing the interaction between processes. So does the adoption of these technologies mean that there is no data exchange between applications? Of course, the answer is no, the powerful Windows system has already designed a lot of solutions for us to solve the communication problem, here we only explore how to use Dynamic Data exchange (DDE) method to achieve data communication between processes.

This instance program functions as follows, the server side has two data items, one is the input string, the other is a timed increment of integers. After running two instances of the program, two programs can establish a DDE connection, implement data transfer, and display data from another instance. The following illustration is a diagram of the effect after the program is compiled:

Diagram One, DDE method realizes the interface effect diagram of interprocess data communication program

One, the realization method

Since Microsoft introduced the Windows operating system, Dynamic Data exchange (DDE) has become a part of Windows, and many WINDWOS applications use DDE technology to achieve data exchange between processes. DDE is a protocol built on the Windows internal messaging system, global and shared global memory, which is used to coordinate data exchange and command invocation between Windows applications, and it has become a common method of communication between applications.

There are four types of DDE applications: Customer type, server type, client/server type, and monitor. A DDE session occurs between a client application and a server application. The client application requests data or services from the server application, and the server application responds to data or service requests from the client application. A client/server application is both a request and a provider of information, and a monitor application is the purpose of the language debugging.

The DDE protocol uses level three tree naming: Service, subject (TOPIC), and data items (item) to identify the data units that DDE is going to transfer. A service enables an application to have data exchange capabilities that are provided to other programs; a topic similar to a directory, is an argument for establishing a session connection: item is the content of the data to be transferred when DDE is specifically communicating, such as a data or a string.

The Dynamic Exchange Management Library (DDEML) provides DDE and application-level protocols. Applications developed using DDEML outperform applications that do not use ddeml, both in terms of running consistency and communication between applications. And the DDEML application makes it much easier to develop applications that support DDE.

After establishing a DDE session, the client program and the server program can exchange data through three kinds of links: 1, Cold Link: Client application data, server program to send data to client immediately; 2, Win Chen: The server program notifies the client that the program data item has changed, However, the value that has occurred has not been sent to the client. 3. Hot Link: When the data item changes, the server program immediately sends the change value to the client program, this is the most commonly used, the most convenient method, the following example uses this method.

DDE Session Initialization

Use API Functions Ddeinitialize () to register applications in DDEML.

Session Establishment

Server: Registration Service Ddenameservice.

Customer: Connect Ddeconnect.

Session process

Similar to the Windows message loop, the process of a session is the process of transaction processing. The customer sends the transaction request through Ddeclienttransaction (), through the DDE callback function, the server processes the customer transaction request, returns Ddecreatedatahandle to send the data, and the customer can call Ddegetdata () to fetch the data.

Session End

May terminate the session by the Service party or the customer side, when launches the program to be able to eliminate the service, releases the resources, invokes Ddeuninitialize ().

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.