thank all of you to have patience to answer my question.
actually,I want to use c lib to store c# object address,
like this:
In c lib, I wrote a structure, and two method operate on
it.
typedef struct
{
void *csharp_obj;
}c_struct;
void set_c_charp_obj(c_struct *cstr, void *csharpObj)
{
cstr->csharp_obj = csharpObj;
}
void *get_c_charp_obj(c_struct *cstr)
{
return cstr->csharp_obj;
}
In C#, I define c lib function prototype:
public extern void SetCCharpObj(IntPtr cStruct, IntPtr
obj);
public extern IntPtr GetCCharpObj(IntPtr cStruct);
then ,you will understand that I want to get C# object
addr and send it as IntPtr to c lib.so that, I store the
pointer of the c# object in c lib for future use.But when
i debug the program, I always get a error.How can I
handle this scenario?and when I fetch the pointer of c#
object, how can i cast it and use it as a object in c#?
thanks
-----Original Message-----
What are you trying to do exactly? There are a couple of
possible differentscenarios here.
Maybe you can just use an object ref.
If you just want a cookie, you could consider using a
GCHandle.If you want to manipulate the contents using pointers,
or pass to unmanagedcode, you can pin the object using the fixed statement,
or perhaps you needsome marshaling/interop help.
Some more info about what you want to do would enable us
to help you better.
"violin" <an*******@discussions.microsoft.com> wrote in
messagenews:02****************************@phx.gbl... I want to get the address of a c# object,and store that
address in a IntPtr value, like we use handle in
VC6.How can i achieve it?
.