* Microsoft.Win32.SafeHandles/SafeRegistryHandle.cs: Implement
ReleaseHandle by pinvoking RegCloseKey if we are on windows, and
nothing otherwise.
* Microsoft.Win32/Win32RegistryApi.cs:
* Microsoft.Win32/RegistryKey.cs: Don't call SafeHandle.Close
from our public api, and do it instead un the windows layer, as
we only support it there for now.
#if NET_4_0
using System;
+using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.ConstrainedExecution;
protected override bool ReleaseHandle ()
{
- throw new NotImplementedException ();
+ // Need to release an unmanaged pointer *only* in Windows.
+ if (Path.DirectorySeparatorChar == '\\')
+ return RegCloseKey (handle) == 0;
+
+ return true;
}
+
+ [DllImport ("advapi32.dll", CharSet = CharSet.Unicode, EntryPoint="RegCloseKey")]
+ static extern int RegCloseKey (IntPtr keyHandle);
}
}
#endif
RegistryApi.Close (this);
handle = null;
#if NET_4_0
- if (safe_handle != null) {
- safe_handle.Close ();
- safe_handle = null;
- }
+ safe_handle = null;
#endif
}
{
if (!IsHandleValid (rkey))
return;
+#if NET_4_0
+ SafeRegistryHandle safe_handle = rkey.Handle;
+ if (safe_handle != null) {
+ // closes the unmanaged pointer for us.
+ safe_handle.Close ();
+ return;
+ }
+#endif
IntPtr handle = GetHandle (rkey);
RegCloseKey (handle);
}