Jun 4, 2016 at 1:44am Jun 4, 2016 at 1:44am UTC
Hello all,
I have a question on native void* to Object^ conversion.
basically I have a native c++ dll which will call a function in my CLI with a void* as a parameter like this:
bool Class1::func1 (int num0,void* pStruct,int num1,int num2)
then in my CLI I will have to convert the void* to an Object^ and pass it to the c# fucntion:
public bool func1(int num0, object pStruct, int num1, int num2)
i'm wondering how can I do that? I'm new to all these native<->managed stuff. Thanks a lot for your help.
by the way, the struct which the void* pointing to is like this:
struct myStruct
{
void* ptr;
int myInt1;
int myInt2;
long mylong1;
};
Jun 5, 2016 at 12:10am Jun 5, 2016 at 12:10am UTC
so you mean in my c# code, i need to have this struct?
public struct myStruct{
IntPtr ptr;
Int32 myInt1;
Int32 myInt2;
Int32 myLong1; //On Windows, longs are 32 bits wide.
};
or in my CLI code?
if in my CLI code, i cast my void* pStruct to Intptr:
IntPtr myIntP = IntPtr(pStruct);
and then I pass myIntP to the C# code, will that work?
thanks a lot again.
Kin
Jun 5, 2016 at 9:33pm Jun 5, 2016 at 9:33pm UTC
Thanks Helios!
somewhat related to the same topic. How do we convert a native "const void* const" pointer to a managed object? I tried the same method as previous:
IntPtr myptr = IntPtr(myConstVoidConstPtr)
it will throw an error