471,071 Members | 1,202 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,071 software developers and data experts.

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 1704

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 leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.