Marshal.PtrToStructure() doesn't work

J

Jay

Hi,

I have a C++ dll in which I decalred on structure like this,

typedef struct doTrnsfr
{
i nt Protocol;

}doTrnsfr;

I am passing this structure to C# code using

SendMessage(HWND_BROADCAST, WM_ASYNCDATA_RECEIVED, 0,(LPARAM)
doTrnsfr);

In C# application I am using MessageWindow class to process this
message.
the structure is defined this way

struct TransferData
{
[MarshalAs(UnmanagedType.I4)]public int proto;
};


protected override void WndProc(ref Message msg)
{

switch (msg.Msg)
{
case WM_ASYNCDATA_RECEIVED:

unsafe
{
TransferData sTemp = new TransferData();
sTemp =
(TransferData)Marshal.PtrToStructure(msg.LParam, typeof
(TransferData));


MessageBox.Show("Hello");

break;
}
}

when I use PtrToStructure() method the application exits without
throwing any exception
and Messagebox Hello is also not getting displayed.
What could be the reason?

Thanks
 

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