468,773 Members | 2,324 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,773 developers. It's quick & easy.

C# Interop - passing structure from UNmanaged to managed code

Hi,

I have a DLL written in C that creates a structure as a local variable, populates it, and then calls a function in managed c#. here is what im talking about:

//-----unmanged code's header file

typedef struct M
{
int a;
int b;
int c;
} MO;

typedef void (*MyCallBack)(MO m)
void register_callback(MyCallBack);

//------unmanged code's .c file

void register_callback(MyCallBack mcb)
{
MO co;
co.a = 67;

mcb(co);

}


-------------managed code (in rough, for brevity)

//struct MO
{
int a;
int b;
int c;
}


delegate void MyDelegate(MO m);

MyDelegate mdg;

mdg += delegate (MO m) {
MessageBox.Show(m.a.ToString());
}

register_callback(mdg);
---------------------------------------------

when I run this code, the managed function does get called by the unmanaged dll code, and the message box pops up showing '67', however after that my program crashes. does anyone know why??

thanks!!
Jun 27 '07 #1
0 1620

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Eric Twietmeyer | last post: by
1 post views Thread by Nadav | last post: by
reply views Thread by nygiantswin2005 | last post: by
3 posts views Thread by ajtaylor | last post: by
5 posts views Thread by Yoavo | last post: by
5 posts views Thread by John | last post: by
reply views Thread by user2008 | last post: by
reply views Thread by zhoujie | last post: by
2 posts views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.