SafeHandle is an abstract class. It wants you to provide an object of a concrete SafeHandle derived class that can release the handle. Unfortunately you forgot to mention how you obtained that IntPtr so we cannot know how it should be released.
I'll take a guess and assume it is a GDI cursor, the one you get from the CreateCursor() winapi function. Which requires calling DestroyCursor() to release the handle. Such a class could look like this:
class SafeCursorHandle : Microsoft.Win32.SafeHandles.SafeHandleZeroOrMinusOneIsInvalid {
public SafeCursorHandle(IntPtr handle) : base(true) {
base.SetHandle(handle);
}
protected override bool ReleaseHandle() {
if (!this.IsInvalid) {
if (!DestroyCursor(this.handle))
throw new System.ComponentModel.Win32Exception();
this.handle = IntPtr.Zero;
}
return true;
}
[System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)]
private static extern bool DestroyCursor(IntPtr handle);
}
Tweak the ReleaseHandle() override as necessary to release the handle in your case.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…