Skylion Skylion - 11 days ago 4
C# Question

How to follow a COM IntPtr in Unity C#?

So I am attempting to follow an unsafe ptr in Unity so I can control the exposure length of a camera. However, I am at a loss of how to actually derefence the ptr. As I understand, the ptr refers to a non-managed object so I need to somehow Marshall it assume? I am unfamiliar with interacting in ptrs in C#. I have already successfully compiled an unsafe version of the code, I just need to figure out what to do with the IntPtr.

For reference, I am using the Hololens Toolkit API. The documentation also suggests I need to release it afterwards. How would I go about access the functions I need to actually call on the VideoDeviceManager.

Answer

You can dereference a pointer by calling Marshal.PtrToStructure. To use it you need to describe your targeted object's layout in your own custom structure type.

Comments