void* to Object^ in C++/CLI

故事扮演 提交于 2019-12-05 19:35:48

Can you make it an IntPtr? What do you expect the client to do with the void*?

If your managed code needs to see the data in the void*:

You can't cast a void* to unmanaged memory to a managed object reference. To turn this into managed memory, you'd have to use Marshal.Copy() or Marshal.PtrToStructure(). That will of course only work if you know the type of the data that the void* points to. source

If your managed code doesn't need to see the data in the void*:

Store it in an IntPtr if your managed code doesn't need to see what it is and just passes it back into the unmanaged code later on. source

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!