How can I send a managed object to native function to use it?

After googling, reading MSDN and try some codes, I found this method to pass a managed object to an unmanaged function This method shows how to convert Object^ to void* and convert void* to Object unsing namespace System; unsing namespace System::Runtime::InteropServices; void managed_function() { Object^ obj = gcnew Object(); // Convert Object^ to void* GCHandle handle = GCHandle::Alloc(obj); IntPtr pointer = GCHandle::ToIntPtr(handle); void* ptr = pointer.ToPointer(); unmanaged_function(ptr); handle->Free(); } void unmanaged_function(void* ptr) { // Convert void* to Object^ IntPtr pointer(ptr); GCHandle handle = GCHandle::FromIntPtr(pointer); Object^ obj = (Object^)handle. Target; obj->SomeManagedMethods(); }.

After googling, reading MSDN and try some codes, I found this method to pass a managed object to an unmanaged function. This method shows how to convert Object^ to void* and convert void* to Object^. Unsing namespace System; unsing namespace System::Runtime::InteropServices; void managed_function() { Object^ obj = gcnew Object(); // Convert Object^ to void* GCHandle handle = GCHandle::Alloc(obj); IntPtr pointer = GCHandle::ToIntPtr(handle); void* ptr = pointer.ToPointer(); unmanaged_function(ptr); handle->Free(); } void unmanaged_function(void* ptr) { // Convert void* to Object^ IntPtr pointer(ptr); GCHandle handle = GCHandle::FromIntPtr(pointer); Object^ obj = (Object^)handle.

Target; obj->SomeManagedMethods(); }.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions