Game Development Reference
In-Depth Information
Caution
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
WM_COPYDATA handler.
LRESULT CALLBACK WinProc(HWND handle,
UINT message,
WPARAM wParam,
LPARAM lParam)
{
switch (message)
{
case WM_COPYDATA:
{
PCOPYDATASTRUCT copyData = (PCOPYDATASTRUCT)lParam;
// Start using the elements in copyData
return 0;
}
}
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.
[StructLayout(LayoutKind.Sequential)]
private struct COPYDATASTRUCT
{
public IntPtr _dataType;
public int _dataSize;
public IntPtr _dataPointer;
}
 
Search Nedrilad ::




Custom Search