I tried to do it like this:
UIntPtr x = (UIntPtr)intPtr;
... but the compiler is not very happy with it and returned a compilation error.
I need to do the conversion because the P / Invoke signature for RegOpenKeyEx requires UIntPtr:
[DllImport("advapi32.dll", CharSet = CharSet.Auto)] public static extern int RegOpenKeyEx( UIntPtr hKey, string subKey, int ulOptions, int samDesired, out UIntPtr hkResult);
To get the handle, I use SafeHandle.DangerousHandle (), which returns IntPtr:
source share