Hi,
I am trying to pass structure in LParam of SendMessage API. I could
not able to get the value in called window.The code and declaration is
as below:
//Class A
//********
[DllImport("User32.Dll" , CharSet=CharSet.Auto)]
private static extern long SendMessage(
IntPtr hWnd, // handle to destination window
UInt32 Msg, // message
UInt32 wParam, // first parameter
ref PassingItem lParam // second parameter
);
[ StructLayout( LayoutKind.Sequential, CharSet=CharSet.Auto )]
public struct PassingItem
{
public long MSISDN;
[MarshalAs(UnmanagedType.LPTStr)]
public string VarifiedStatus;
}
public const int WM_USER = 0x0400;
public const int MSG_COMMAND_OPEN = WM_USER + 200;
PassingItem PI;
PI.MSISDN = 123;
PI.VarifiedStatus = "Varified";
SendMessage ((IntPtr)hwnd, MSG_COMMAND_OPEN, 0, ref PI);
//Class B
//*******
public const int WM_USER = 0x0400;
public const int MSG_COMMAND_OPEN = WM_USER + 200;
public struct PassingItem
{
public long MSISDN;
public string VarifiedStatus;
}
protected override void WndProc(ref Message m)
{
if(m.Msg == MSG_COMMAND_OPEN)
{
PassingItem PI = (PassingItem)Marshal.PtrToStructure((IntPtr)m.LParam,typeof(PassingItem));
//value trying to display
//************************
MessageBox.Show(PI.MSISDN.ToString());
}
else
{
base.WndProc(ref m);
}
}
In the Messagebox it showing 0 value for MSISDN, which is not correct.
Could anybody let em know ASAP what is the problem in my code
Thanks,
Anand
Mattias Sj?gren - 03 Nov 2003 23:56 GMT
>In the Messagebox it showing 0 value for MSISDN, which is not correct.
>Could anybody let em know ASAP what is the problem in my code
If the windows run in different processes, you must use a message that
Windows knows how to marshal cross process boundaries, such as
WM_COPYDATA.
Mattias

Signature
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.