Using message to implement internal process communication under VC + + 6.0

Source: Internet
Author: User

There are several ways of internal interprocess communication and data exchange: messages, shared memory, Anonymous (named) pipes, postal slots, Windows Sockets, and many other technologies. While using the message mechanism to realize IPC, although compared with other methods, there are some disadvantages such as small amount of exchanged data and less information, but it is widely used in internal process communication system without large and frequent data exchange because of its convenience and flexible application, especially for the The command and response between the layer master software and the underlying working software can show its good performance more fully. This paper expounds how to use vc++6.0 to realize internal process communication by compiling a main control software and a bottom-working software of its operation.

First, Windows Messaging mechanism

Windows is an object-oriented architecture in which Windows environments and applications interact through messages. After the Windows application starts executing, Windows creates a message queue for the program that holds messages that are mailed to various different windows that the program might create. The structure of messages in Message Queuing (MSG) is:

typedef struct tagMSG{
HWND hwnd;
UINT message;
WPARAM wParam;
LPARAM lParam;
DWORD time;
POINT pt;
}MSG;

The first member variable is the window handle that identifies the window that receives the message, and the second parameter is the message identification number, such as WM_PAINT, and the third and fourth arguments are related to the message value, all of which are messages parameters. The first four parameters are very important and often used, as the latter two parameters represent the time of the mailing message and the cursor position (screen coordinates) respectively. There are two ways to send messages to an application: The system sends the message "POST" to the application's message queue, which is the incoming message Win32 API has the corresponding function:

PostMessage (), this function returns without waiting for the message to be processed, and the other is the window function that the system sends the message "send" to the application when it calls the window function directly, and the function that belongs to "no team message" is SendMessage () It must wait for the message to be processed before it can be returned.

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.