Marshalling Pointer In Structure Problem?

K

Kevin Hutchison

I have a C program sample that I am reproducing, line for line in C# as I
write our wrapper for a 3rd party library. The problem I believe I am
having is related to marshalling a pointer in a structure. The C definition
of the structure is:

typedef struct _HSAFE
{
void *pHandleData;
unsigned long u32Check;
} HSAFE ;

C# version ...

struct HSAFE{
IntPtr pHandleData;
uint u32Check;
}

When the function "ERROR Initialize( HSAFE *phSafe )" is called in C, it
ALWAYS, ALWAYS, ALWAYS returns the same values for pHandleData and u32Check.

When the C# equivalent function "public static extern ERROR Initialize( ref
HSAFE phSafe )" is called, it ALWAYS ALWAYS ALWAYS returns the same value
for u32Check, but pHandleData is different/wrong (the data at that location
is 0). Subsequent calls fail using the returned HSAFE.

Any thoughts?
 

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