mirror of https://github.com/dahall/Vanara.git
Changed calls from conversion operator to DangerousGetHandle for all GenericSafeHandle derivatives.
parent
20d3d2df0d
commit
bbc22f6646
|
@ -1789,7 +1789,8 @@ namespace Vanara.PInvoke
|
||||||
var hLib = LoadLibraryEx(fileName, IntPtr.Zero, flags);
|
var hLib = LoadLibraryEx(fileName, IntPtr.Zero, flags);
|
||||||
if (hLib.IsInvalid)
|
if (hLib.IsInvalid)
|
||||||
throw new Win32Exception();
|
throw new Win32Exception();
|
||||||
SetHandle((IntPtr)hLib);
|
SetHandle(hLib.DangerousGetHandle());
|
||||||
|
hLib.SetHandleAsInvalid();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Initializes a new instance of the <see cref="SafeLibraryHandle"/> class.</summary>
|
/// <summary>Initializes a new instance of the <see cref="SafeLibraryHandle"/> class.</summary>
|
||||||
|
|
|
@ -932,7 +932,7 @@ namespace Vanara.PInvoke
|
||||||
cnt = cnt << 1;
|
cnt = cnt << 1;
|
||||||
var h = new SafeProcessHeapBlockHandle((uint)Marshal.SizeOf(typeof(uint)) * cnt);
|
var h = new SafeProcessHeapBlockHandle((uint)Marshal.SizeOf(typeof(uint)) * cnt);
|
||||||
var c = GetConsoleProcessList(h, cnt);
|
var c = GetConsoleProcessList(h, cnt);
|
||||||
if (c >= 1 && c <= cnt) return ((IntPtr)h).ToArray<uint>((int)c);
|
if (c >= 1 && c <= cnt) return h.DangerousGetHandle().ToArray<uint>((int)c);
|
||||||
} while (cnt > 0);
|
} while (cnt > 0);
|
||||||
throw Win32Error.GetLastError().GetException();
|
throw Win32Error.GetLastError().GetException();
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ namespace Vanara.InteropServices.Tests
|
||||||
{
|
{
|
||||||
var h = new GenericSafeHandle(p => true);
|
var h = new GenericSafeHandle(p => true);
|
||||||
Assert.That(h.IsInvalid && h.DangerousGetHandle() == IntPtr.Zero);
|
Assert.That(h.IsInvalid && h.DangerousGetHandle() == IntPtr.Zero);
|
||||||
Assert.That(IntPtr.Zero.Equals((IntPtr)h));
|
Assert.That(IntPtr.Zero.Equals(h.DangerousGetHandle()));
|
||||||
h.Dispose();
|
h.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -385,15 +385,15 @@ namespace Vanara.PInvoke.Tests
|
||||||
{
|
{
|
||||||
var ph = new SafeProcessHeapBlockHandle(512);
|
var ph = new SafeProcessHeapBlockHandle(512);
|
||||||
var fw = new WIN32_FIND_DATA {ftCreationTime = DateTime.Today.ToFileTimeStruct(), cFileName = "test.txt", dwFileAttributes = FileAttributes.Normal};
|
var fw = new WIN32_FIND_DATA {ftCreationTime = DateTime.Today.ToFileTimeStruct(), cFileName = "test.txt", dwFileAttributes = FileAttributes.Normal};
|
||||||
Marshal.StructureToPtr(fw, (IntPtr)ph, false);
|
Marshal.StructureToPtr(fw, ph.DangerousGetHandle(), false);
|
||||||
Assert.That(Marshal.ReadInt32((IntPtr)ph), Is.EqualTo((int)FileAttributes.Normal));
|
Assert.That(Marshal.ReadInt32(ph.DangerousGetHandle()), Is.EqualTo((int)FileAttributes.Normal));
|
||||||
Assert.That(ph.Size, Is.EqualTo(512));
|
Assert.That(ph.Size, Is.EqualTo(512));
|
||||||
|
|
||||||
using (var hh = HeapCreate(0, IntPtr.Zero, IntPtr.Zero))
|
using (var hh = HeapCreate(0, IntPtr.Zero, IntPtr.Zero))
|
||||||
{
|
{
|
||||||
var hb = hh.GetBlock(512);
|
var hb = hh.GetBlock(512);
|
||||||
Marshal.StructureToPtr(fw, (IntPtr)hb, false);
|
Marshal.StructureToPtr(fw, hb.DangerousGetHandle(), false);
|
||||||
Assert.That(Marshal.ReadInt32((IntPtr)hb), Is.EqualTo((int) FileAttributes.Normal));
|
Assert.That(Marshal.ReadInt32(hb.DangerousGetHandle()), Is.EqualTo((int) FileAttributes.Normal));
|
||||||
Assert.That(hb.Size, Is.EqualTo(512));
|
Assert.That(hb.Size, Is.EqualTo(512));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -586,7 +586,7 @@ namespace Vanara.Windows.Shell
|
||||||
throw new InvalidOperationException("Thumbnails are not supported by this item.");
|
throw new InvalidOperationException("Thumbnails are not supported by this item.");
|
||||||
hres.ThrowIfFailed();
|
hres.ThrowIfFailed();
|
||||||
//Marshal.ReleaseComObject(fctry);
|
//Marshal.ReleaseComObject(fctry);
|
||||||
return GetTransparentBitmap((IntPtr)hbitmap);
|
return GetTransparentBitmap(hbitmap.DangerousGetHandle());
|
||||||
}
|
}
|
||||||
if (!flags.IsFlagSet(ShellItemGetImageOptions.IconOnly))
|
if (!flags.IsFlagSet(ShellItemGetImageOptions.IconOnly))
|
||||||
return GetThumbnail(size.Width);
|
return GetThumbnail(size.Width);
|
||||||
|
|
Loading…
Reference in New Issue