Game Development Reference
The Companion Web site contains a robust wrapper and manager around
WM_COPYDATA . There is a version for managed applications and also a version for
Communicating from Unmanaged Applications
In order to focus purely on the implementation details behind WM_COPYDATA ,we will
first look at usage from an unmanaged application so we can avoid Platform
The WM_COPYDATA message is sent to an application by calling the SendMessage()
method; the PostMessage() method should not be used. The first parameter is the
window handle of the target you are sending the data to; this handle will be refer-
encing a window that is in use by another application. The second parameter is the
event ID that is being sent. In this case we are using the WM_COPYDATA identifier. The
third parameter ( WPARAM ) is the handle of the window that is sending the data.
Finally, the last parameter ( LPARAM ) is a pointer to a COPYDATASTRUCT structure that
contains the data that will be sent to the other application.
COPYDATASTRUCT has three members: dwData allows you to send 32 bits of data, and
the remaining two members are used to pass a pointer to the other application.
The cbData member describes the data length (in bytes) that is pointed to by the
member lpData . You do not have to pass a pointer; lpData can be null if you just
wish to pass values in dwData .
copyData.dwData = 0;
copyData.cbData = dataPointerSize;
copyData.lpData = dataPointer;
The following code shows how to construct the SendMessage() call. That's all there
is to sending data with WM_COPYDATA !
BOOL success = (GetLastError() == 0 ? 1 : 0);
In order to receive WM_COPYDATA messages, you must add a message handler in the
Windows message processing loop. When a WM_COPYDATA message is received, you
have a pointer to a COPYDATASTRUCT instance where you can extract the data sent to