Initial data: there is a WinAPI C ++ application (server). The application knows the Windows Form C # application process handle (client). The server creates the data and sends it to the client:
COPYDATASTRUCT cds; cds.dwData = 1; cds.lpData = "dddd"; cds.cbData = 4; PostMessage(hwnd/*повторюсь, дескриптор получателя известен*/, WM_COPYDATA, NULL, (LPARAM)&cds); Further, the client must accept them. I accept this:
[StructLayout(LayoutKind.Sequential)] struct COPYDATASTRUCT { public IntPtr dwData; public int cbData; public IntPtr lpData; } private const int WM_COPYDATA = 0x004A; protected override void WndProc(ref Message m) { switch(m.Msg) { case WM_COPYDATA: { string message = ""; unsafe { COPYDATASTRUCT* cds = (COPYDATASTRUCT*)m.LParam; message = Marshal.PtrToStringAnsi(cds->lpData); } this.Log.Text += message; // Log - это richtextbox break; } } base.WndProc(ref m); } However, the client does not catch the message (changes in the richtextbox) is not fixed. What is the trouble? Thank. PS: looked in spy - the message does not come.
"dddd"is local data. You need a pointer to the data in the heap, no? Otherwise, another process runs the risk of garbage. - Alexander PetrovMarshal.PtrToStringAnsi(cds->lpData);? What do you have on the index? Look in the debugger. - VladD