Passing Pointers from manged to unmanged code

G

Germic

Hi,

I want to create an Hashtable in C# and pass an pointer to the hashtable to
a C code.
Later, the C code could reference the hashtable by passing the pointer to
the hashtable as a ref parameter.
what is the correct way to do this?

Thanks,
 
B

Benoit Vreuninckx

Germic said:
Hi,

I want to create an Hashtable in C# and pass an pointer to the hashtable to
a C code.
Later, the C code could reference the hashtable by passing the pointer to
the hashtable as a ref parameter.
what is the correct way to do this?

Thanks,

You can't pass complex data structures, like a Hashtable, to native
code. Only primitive types, like integers, floats, strings, arrays of
those types, POD's, ... can be passed back and forth between managed and
native code.
A starting point: MarshalAsAttribute, StructLayoutAttribute, ...
Converting data to pass it from managed to unmanaged code (and back) is
called *marshalling*.

Cheers,
Benoit
 
M

Michael Groeger

you could try to expose your assembly as a COM component. then you write
accessors inside your assembly which manipulate your hashtable....
 
G

Germic

Hi Michael,

Thanks for your suggestions. Could you pls explain a bit more on this. I am
quite new to C# & Interop

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