Hi
I tried to implement a C++ dll and a Visual Basic .net application, which is able to receive WM_COPYDATA messages from the DLL. Here's my code
DLL
typedef struct _TRANSTA
char teststr[300]
}TRANSTAG
TRANSTAG trans
COPYDATASTRUCT MyCDS
CString test
test = "This is a test."
memcpy(trans.teststr,test,test.GetLength())
MyCDS.cbData = test.GetLength()
MyCDS.lpData = &trans
HWND hwDispatch = FindWindow( NULL, "Form1" )
if( hwDispatch != NULL
SendMessage( hwDispatch
WM_COPYDATA
(WPARAM)(HWND) NULL
(LPARAM) (LPVOID) &MyCDS )
Now, here's the code in the VB.NET application
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> Structure TRANSTA
Public test As Strin
End Structur
Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (<MarshalAsAttribute(UnmanagedType.AsAny)> ByVal hpvDest As Object, <MarshalAsAttribute(UnmanagedType.AsAny)> ByVal hpvSource As Object, ByVal cbCopy As Long
Protected Overrides Sub WndProc(ByRef m As Message
Select Case (m.Msg
Case WM_COPYDAT
NewMessage(m.LParam
Me.Invalidate(
End Selec
MyBase.WndProc(m
End Su
Public Sub NewMessage(ByVal lparam As IntPtr
Dim cds As New COPYDATASTRUC
Dim d As New TRANSTA
CopyMemory(cds, lparam, Len(cds)
CopyMemory(d, cds.lpData, cds.cbData
MsgBox(d.test
End Su
The problem is that the received string doesn't contain anything: The message WM_COPYDATA is captured successfully, but d.test is just empty. Any ideas why
Thank
Gordon