[Communication between IPC processes 4] Data Replication message WM_COPYDATA

Source: Internet
Author: User

IPC inter-process communication + Data Replication message WM_COPYDATAIPC (Inter-Process Communication ).The Data Replication message WM_COPYDATA is a special message in Windows, which can be used to transmit data between processes.
1. WM_COPYDATA:
A WM_COPYDATA message contains two parameters: WPARAM wParam and LPARAM lParam. WPARAM and LPARAM are Hungarian numerics, with historical changes. WPARAM indicates a 32-bit integer variable, and LPARAM indicates a 32-bit integer variable pointer. When WM_COPYDATA is sent, wParam is assigned to the window for sending the message, and lParam points to a COPYDATASTRUCT structure.:TypedefStruct {ULONG_PTR dwData;DWOED cdData;PVOID lpData;};In this struct, dwData can set any value. lpData is the data address that needs to be sent to the process in which the window is located, and cbData is the number of bytes of data sent by lpData.When a WM_COPYDATA message is sent, the system sends the content directed to COPYDATASTRUCT and lpData to the target process. After receiving the WM_COPYDATA message, the target process can extract data from the lParam parameter.
2. WM_COPYDATA Sender:
Create window-> Fill in COPYDATASTRUCT-> SendMessage to send WM_COPYDATA data.COPYDATASTRUCT cds; // defines the COPYDATASTRUCT variableSendMessage(Hwndto, // target window handle(UINT) WM_COPYDATA, // specify the data to be sent(WPARAM) hwndfrom, // configure the source window handle as the WPARAM Parameter(LPARAM) & cds // use COPYDATASTRUCT as the LPARAM Parameter);
3. WM_COPYDATA receiving end:Use the lPrama parameter to obtain COPYDATASTRUCT-> extract data from COPYDATASTRUCT.COPYDATASTRUCT * PointCds = (COPYDATASTRUCT *) lParam;PointCds-> lpData is the transmitted data.4. Cow test:
As the test procedure involves window creation, it is complicated to attach a project file:Sender: Click to downloadAcceptor: Click to downloadThe compiling environment of the appeal program is VS 2012.The Appeal Procedures refer to the book "proficient in Windows APIs.

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.