I have created a custom windows message and using SendNotifyMessage
(user32.dll) the message is sent (broadcasted).
I send the message as follows:
[DllImport("user32.dll", CharSet=CharSet.Auto)]
private static extern int SendNotifyMessage(IntPtr hwnd, IntPtr
wMsg,
IntPtr wParam,
IntPtr lParam);
SendNotifyMessage((IntPtr)0xffff, RegisterWindowMessage("somestring"),
Marshal.StringToHGlobalAuto("a message"),
Marshal.StringToHGlobalAuto("another message"));
I am receiving the message in another c# app as follows:
protected override void
WndProc(ref System.Windows.Forms.Message m)
{
if(m.Msg == RegisterWindowMessage("somestring"))
{
string s = Marshal.PtrToStringAuto(m.WParam);
}
else
{
base.WndProc(ref m);
}
}
The message is received in WndProc without any problems, however the
lparam and wparam properties (when marshalled) have empty strings.
It seems that the pointer created in the sendmessage call points to a
section in memory that when in the WndProc call points to nothing at
all.
When I inspect the memory location in the app that sends the message,
the messages are in fact there.
Does anyone have any advice or suggestions as to what might be wrong?
Thanks in advance.
Ryan Fransen