Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / November 2003

Tip: Looking for answers? Try searching our database.

Problem in Passing structure to SendMessage API

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Anand - 31 Oct 2003 00:16 GMT
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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.