M
Mo
hello,
i am using sendmessage() to send a char* string from evc app to vb.net
app
i get the first sendmessage(), display the string and then
it seems that sendmessage() doesnt return 1 to the evc app.
my evc locks up and doesnt display any other data after i send the
first message
below is my code from the two app's
<evc code>
char s1[]=TEXT("3505.4543");
char s2[]=TEXT("moredata");
char s3[]=TEXT("moredata2");
int result;
static COPYDATASTRUCT copydata;
copydata.dwData = NULL;
copydata.cbData = strlen(s1) + 1;
copydata.lpData = s1;
result=SendMessage(HWND_BROADCAST, WM_COPYDATA, NULL, (LPARAM)
©data);
printf("message 1 result\r\n",result);
Sleep(3000);
copydata.dwData = NULL;
copydata.cbData = strlen(s2) + 1;
copydata.lpData = s2;
result=SendMessage(HWND_BROADCAST, WM_COPYDATA,NULL, (LPARAM)
©data);
printf("message 2 result=%d\r\n",result);
Sleep(3000);
copydata.dwData = NULL;
copydata.cbData = strlen(s3) + 1;
copydata.lpData = s3;
result=SendMessage(HWND_BROADCAST, WM_COPYDATA, NULL, (LPARAM)
©data);
printf("message 3 result=%d\r\n",result);
</evc code>
my vb.net code
<vb>
Const WM_APP = &H8000
Const WM_COPYDATA = &H4A
<StructLayout(LayoutKind.Sequential)> _
Private Structure COPYDATASTRUCT
Public dwData As Integer
Public cbData As Integer
Public lpData As Integer
End Structure
......
Protected Overrides Sub WndProc(ByRef msg As Message)
Select Case (msg.Msg)
Case WM_COPYDATA
frmMain.txtInformation.Text += "WM_COPYDATA" + vbNewLine
'get the standard message structure from lparam
Dim CD As COPYDATASTRUCT =
System.Runtime.InteropServices.Marshal.PtrToStructure(msg.LParam,
CD.GetType)
'setup byte array
Dim B() As Byte
'get array length from cd
ReDim B(CD.cbData)
'get pointer to data from cd
Dim lpData As IntPtr = New IntPtr(CD.lpData)
'copy data from memory into array
Marshal.Copy(lpData, B, 0, CD.cbData)
'get as string and display in label
frmMain.txtInformation.Text += Encoding.Default.GetString(B, 0,
B.Length)
'empty array
Erase B
'set message result to 'true', meaning message handled
msg.Result = New IntPtr(1)
frmMain.txtInformation.Text += "message processed"
End Select
MyBase.WndProc(msg)
End Sub
</vb>
although i set the msg.Result to 1 to indicate to th evc app that
sendmessage() has been processed, it still doesnt work, i only get the
first message in my vb app, and the evc app doesnt display none of its
printf() statements
regards
i am using sendmessage() to send a char* string from evc app to vb.net
app
i get the first sendmessage(), display the string and then
it seems that sendmessage() doesnt return 1 to the evc app.
my evc locks up and doesnt display any other data after i send the
first message
below is my code from the two app's
<evc code>
char s1[]=TEXT("3505.4543");
char s2[]=TEXT("moredata");
char s3[]=TEXT("moredata2");
int result;
static COPYDATASTRUCT copydata;
copydata.dwData = NULL;
copydata.cbData = strlen(s1) + 1;
copydata.lpData = s1;
result=SendMessage(HWND_BROADCAST, WM_COPYDATA, NULL, (LPARAM)
©data);
printf("message 1 result\r\n",result);
Sleep(3000);
copydata.dwData = NULL;
copydata.cbData = strlen(s2) + 1;
copydata.lpData = s2;
result=SendMessage(HWND_BROADCAST, WM_COPYDATA,NULL, (LPARAM)
©data);
printf("message 2 result=%d\r\n",result);
Sleep(3000);
copydata.dwData = NULL;
copydata.cbData = strlen(s3) + 1;
copydata.lpData = s3;
result=SendMessage(HWND_BROADCAST, WM_COPYDATA, NULL, (LPARAM)
©data);
printf("message 3 result=%d\r\n",result);
</evc code>
my vb.net code
<vb>
Const WM_APP = &H8000
Const WM_COPYDATA = &H4A
<StructLayout(LayoutKind.Sequential)> _
Private Structure COPYDATASTRUCT
Public dwData As Integer
Public cbData As Integer
Public lpData As Integer
End Structure
......
Protected Overrides Sub WndProc(ByRef msg As Message)
Select Case (msg.Msg)
Case WM_COPYDATA
frmMain.txtInformation.Text += "WM_COPYDATA" + vbNewLine
'get the standard message structure from lparam
Dim CD As COPYDATASTRUCT =
System.Runtime.InteropServices.Marshal.PtrToStructure(msg.LParam,
CD.GetType)
'setup byte array
Dim B() As Byte
'get array length from cd
ReDim B(CD.cbData)
'get pointer to data from cd
Dim lpData As IntPtr = New IntPtr(CD.lpData)
'copy data from memory into array
Marshal.Copy(lpData, B, 0, CD.cbData)
'get as string and display in label
frmMain.txtInformation.Text += Encoding.Default.GetString(B, 0,
B.Length)
'empty array
Erase B
'set message result to 'true', meaning message handled
msg.Result = New IntPtr(1)
frmMain.txtInformation.Text += "message processed"
End Select
MyBase.WndProc(msg)
End Sub
</vb>
although i set the msg.Result to 1 to indicate to th evc app that
sendmessage() has been processed, it still doesnt work, i only get the
first message in my vb app, and the evc app doesnt display none of its
printf() statements
regards