How to convert a "void*" to managed class
-
Hi, I need to convert a "void*" pointer to a managed class. How can I do it? Soppose: ---------------- void * pClass ref class A {}; A^ pA = pClass; <---- compile error --------------------- Best,
Maybe something like...
System::Runtime::InteropServices::GCHandle gch = System::Runtime::InteropServices::GCHandle::FromIntPtr((System::IntPtr)pClass);
A ^pA = (A ^)gch.Target;Of course, this assumes pClass was obtained from an IntPtr obtained from an actual managed reference to an "A" object...
Mark Salsbery :java:
-
Hi, I need to convert a "void*" pointer to a managed class. How can I do it? Soppose: ---------------- void * pClass ref class A {}; A^ pA = pClass; <---- compile error --------------------- Best,
-
Hi, I suggest you to use a dynamic cast : dynamic_cast msdn[^] Best regards! EL GAABEB.
-
Hi, I need to convert a "void*" pointer to a managed class. How can I do it? Soppose: ---------------- void * pClass ref class A {}; A^ pA = pClass; <---- compile error --------------------- Best,
transoft wrote:
I need to convert a "void*" pointer to a managed class. How can I do it?
To start with, based on your other post.... You must NOT attempt to cast an unmanaged class to a managed one. Doesn't matter why you think that is a good idea because it isn't.
-
transoft wrote:
I need to convert a "void*" pointer to a managed class. How can I do it?
To start with, based on your other post.... You must NOT attempt to cast an unmanaged class to a managed one. Doesn't matter why you think that is a good idea because it isn't.