In: Computer Science
Windows WM_COPYDATA message will be used to send data to another process. Every windows message has two parameters – WPARAM and LPARAM. One needs to set both follows:
WPARAM: A handle to window passing the data
LPARAM: A pointer to a COPYDATASTRUCT structure that contains the
data to be passed.
Source code(C++)
SendMessage(hwnd, // Handle to destination window
WM_COPYDATA, // Message to send to destination window
(WPARAM)wparam, // Handle to window passing the data
(LPARAM)lparam); // Data (pointer to COPYDATASTRUCT)
CString sMsg(_T("Hello this message is from
WM_COPYDATA"));
COPYDATASTRUCT data;
data.dwData = 1;
data.cbData = sMsg.GetLength()*sizeof(WCHAR);
data.lpData = &sMsg;
HWND destWnd = FindWindow(_T("WinClassName"),
_T("WindowName"));
SendMessage(destWnd, WM_COPYDATA, (WPARAM)(HWND)hwnd,
(LPARAM)(LPVOID)&data);
The receiving application should implement the WM_COPYDATA message
in its message loop and would retrieve as follows:
case WM_COPYDATA:
PCOPYDATASTRUCT pcData;
pcData = (PCOPYDATASTRUCT) lParam;
CString* sRecvMsg = pcData->lpData;
break;