thanks Mattias but :
[quoted text, click to view] >>class MyUnmanagedStruct
>>{
>> int foo;
>>}
>>class StructOwner
>>{
>> MyUnmanagedStruct uStruct; // i would like this reference points to
>> the
>>unmanaged struct
>
> You can never make a reference type variable point to something that
> isn't allocated off the managed GC heap. You'll have to make
> MyUnmanagedStruct a struct in the C# code instead and then either
> store the pointer as a "real" pointer (MyUnmanagedStruct* - requires
> use of unsafe code) or as an IntPtr.
how can I convert (cast) the IntPtr coming from the unmanaged code to my
unmanaged structure :
******************************************************
c++
******************************************************
__declspec(dllexport) void GetAPtrToAnUnmanagedStruct( MyUnmanagedStruct **
ptr);
void GetAPtrToAnUnmanageStruct( MyUnmanagedStruct ** ptr)
{
*ptr = new MyUnmanagedStruct();
}
******************************************************
c#
******************************************************
[dllImport]
void GetAPtrToAnUnmanagedStruct( ref IntPtr ptr);
struct MyUnmanagedStruct
{
int foo;
}
class StructOwner
{
IntPtr ptrToAnUnmanagedStructure;
MyUnmanagedStruct localUnmanagedStructure;
InitPtr()
{
GetAPtrToAnUnmanagedStruct( ref ptrToAnUnmanagedStructure);
}
RefreshLocalData()
{
localUnmanagedStructure = (MyUnmanagedStruct)
ptrToAnUnmanagedStructure; /// how do I cast the IntPtr ????
}
}
what I want to do is to have a memory zone shared between a unmanaged c++
dll and a c# application.
in another words, I want to have structure that can be seen and modified in
both worlds.
(I can't make a managed c++ wrapper).
thanks
Antoine