Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Your CString may be in the struct, but the memory to store it is allocated on the heap. You have to go low-tech here: put a wchar (or char, or TCHAR depending upon your desires) array in the ShareMessage struct and copy the string contents to that array. In your receiver code, read the string out of the wchar array. Oh, and you have sent the address of YOUR struct, not the COPYDATASTRUCT, and sent it to yourself, not the other dialog. modify the SendMessage call like this:</p> <pre><code>SendMessage (hWnd,WM_COPYDATA,(WPARAM)hwnd,(LPARAM)(LPVOID)&amp;cData); </code></pre> <p>Also, are you SURE the FindWindow call is working? That class name looks very suspicious to me. Better to use NULL, and rely on the window title. I have this vague memory that MFC dialogs have a fixed class name.</p> <p>Your code should work then.</p> <p>For example:</p> <pre><code>typedef struct ShareMessage { wchar szMyString [100]; int myValue; }MYDATA; void CCopyDataDlg::OnBnClickedOk() { MYDATA myData; COPYDATASTRUCT cData; ZeroMemory (&amp;myData, sizeof(myData); wcscpy (myData.szMyString, (L"Rakesh")); cData.dwData = ORGININFO; cData.cbData = sizeof(myData); cData.lpData = &amp;myData; ... </code></pre> <p>I haven't tested that code, it's off the top of my head. I assumed wchar because you used the L modifier on your constant string.</p> <p>Additionally, in your receiver code you have this line:</p> <pre><code>if (WM_COPYDATA != NULL) </code></pre> <p>which doesn't make sense. I assume you meant to test the received message number against the constant WM_COPYDATA.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload