Game Development Reference
The receiving application should consider the data read-only, as the data is only valid during pro-
cessing. The receiving application should also not attempt to free the memory sent to it. If the
receiving application needs to manipulate the data, it should store a local copy.
The following code shows a culled version of a message handler, only showing the
LRESULT CALLBACK WinProc(HWND handle,
PCOPYDATASTRUCT copyData = (PCOPYDATASTRUCT)lParam;
// Start using the elements in copyData
return DefWindowProc(handle, message, wParam, lParam);
Communicating from Managed Applications
Using WM_COPYDATA from a managed application is pretty much identical to using it
from an unmanaged application, except that we need to declare some of the types
and identifiers we will need.
The following code shows the P/Invoke signature for the COPYDATASTRUCT type.
private struct COPYDATASTRUCT
public IntPtr _dataType;
public int _dataSize;
public IntPtr _dataPointer;