Message function:
Sharing data between processes (internally by creating a memory-mapped file)
Message Description:
Data structure/type to use:
typedef struct TAGCOPYDATASTRUCT {
ULONG_PTR Dwdata;
DWORD cbdata;
PVOID lpdata;
} copydatastruct, *pcopydatastruct;
Structure parameter Description:
Dwdata (ULONG) holds a value that can be used as a marker, etc.
Lpdata (void*) The starting address of the data to be sent (can be null)
Cbdata (DWORD) length of data to be sent
Parameters of the message:
HWND: Handle to the window that receives the data
WParam: The window handle that transmits the data (null also doesn't matter)
Address of the LPARAM:COPYDATASTRUCT type variable
Examples of Use:
copydatastruct CDs; Char " Girls Don't Cry " ; 0 ; = msg; = strlen (msg) +1// string Please remember to add ' plus ', otherwise it's wrong, here is the ANSI string SendMessage (FindWindow ( " Nbsg_class " 0, (LPARAM) &cds);
Note: If you are sending a string of type CString, you can do so
CString str = _t (" girl does not cry "); char* msg = str. GetBuffer (0);
So that it can be converted into a char* type.
--------------------------------------------
A possible processing of the message by the receiving end:
BOOL Cxuanzedlg::oncopydata (cwnd* pWnd, copydatastruct* pcopydatastruct) { // TODO: Add the message handler code here and/or call the default value copydatastruct* PCDS = (copydatastruct*) pcopydatastruct; CString Str ((Char*) pcds->lpdata); Str. Format (_t ("%s flag:%d"), str, pcds->dwdata); AfxMessageBox (str); return Cdialogex::oncopydata (pWnd, pcopydatastruct);}
Description
Passing data using the WM_COPYDATA message is actually the data that will be passed to the shared memory, and the address is passed to the other process.
In this message, there is a flag dwdata this data is a ULONG_PTR type, an unsigned long integer, which can be used as a flag for the data. Such different flags can be used for different uses of the data passed!
VC + + in two programs to pass a constant value such as String method: Using the WM_COPYDATA message of the