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.