Receive WM_COPYDATA from unmanaged application

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,
my .NET program (Compact Framework) send to another my application
(unmanaged) a WM_COPYDATA message. My unmanaged application receive correctly
data from .NET application. Now my unmanaged application must be able to send
the same COPYDATASTRUCT struct thougth another WM_COPYDATA to my .NET
application. This .NET application receive message, but is not correct.
The code of my unmanaged app is:
BOOL CMainFrame::OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct)
{
switch(pCopyDataStruct->dwData)
{
case ID_REQUEST_DOWNLOAD_DWNSERVER:
if(m_hWndDWnServer != NULL)
{
::SendMessage(m_hWndDWnServer, WM_COPYDATA, (WPARAM)0,
(LPARAM)&pCopyDataStruct);
}
break;
default:
break;
}
return CFrameWnd::OnCopyData(pWnd, pCopyDataStruct);
}
The code of my .NET app is:
protected override void WndProc(ref Message msg)
{
switch (msg.Msg)
{
case Win32.WM_COPYDATA:
unsafe
{
Win32.COPYDATASTRUCT st =
(Win32.COPYDATASTRUCT)Marshal.PtrToStructure(msg.LParam,
typeof(Win32.COPYDATASTRUCT));
string str = Marshal.PtrToStringUni(st.lpData, st.cbData);
}
break;
default:
base.WndProc(ref msg);
break;
}
}
str String does not contains the correct value. Why ?
 
In my managed code COPYDATASTRUCT is wrapped in :
[StructLayout(LayoutKind.Sequential)]
internal struct COPYDATASTRUCT
{
public int dwData;
public int cbData;
public IntPtr lpData;
}
 
I'm using a pCopyDataStruct parameter in input at OnCopyData method in my
unmanaged code. Is it correct ?
 
OK, let me get this straight. You send WM_COPYDATA message from managed code
to unmanaged and then you forward the same message to the managed app again
without any changes? Make sure that the data that you inititally send from
managed app is pinned. Otherwise it could be mive or destroyed by the GC.
 
Back
Top