all groups > dotnet interop > october 2003 >
You're in the

dotnet interop

group:

Problem in Passing structure to SendMessage API


Problem in Passing structure to SendMessage API anand.dani NO[at]SPAM T-Mobile.com
10/30/2003 3:16:45 PM
dotnet interop: 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,

Re: Problem in Passing structure to SendMessage API Mattias Sjögren
11/4/2003 12:56:35 AM

[quoted text, click to view]

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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
AddThis Social Bookmark Button