sendmessage not returnning

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)
&copydata);
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)
&copydata);
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)
&copydata);
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
 
P

Paul G. Tobey [eMVP]

Well, you're broadcasting it, so every top-level window in the system gets
it. One of them is probably not processing it, leaving your application in
SendMessage. Why are you using a broadcast to send the message to the one
target you have?

Paul T.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top