-
Notifications
You must be signed in to change notification settings - Fork 0
/
NativeLibraryHandle.cs
50 lines (39 loc) · 1.26 KB
/
NativeLibraryHandle.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//
// @(#) NativeLibraryHandle.cs
//
// Project: usis.Data.LocalDb
// System: Microsoft Visual Studio 2022
// Author: Udo Schäfer
//
// Copyright (c) 2018-2023 usis GmbH. All rights reserved.
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;
namespace usis.Data.LocalDb
{
// -------------------------
// NativeLibraryHandle class
// -------------------------
internal sealed class NativeLibraryHandle : SafeHandleZeroOrMinusOneIsInvalid
{
#region construction
// ------------
// construction
// ------------
public NativeLibraryHandle(string fileName) : base(true)
{
var handle = NativeMethods.LoadLibraryEx(fileName, IntPtr.Zero, 0);
if (handle == IntPtr.Zero) throw new Win32Exception(Marshal.GetLastWin32Error());
SetHandle(handle);
}
#endregion
#region overrides
// --------------------
// ReleaseHandle method
// --------------------
protected override bool ReleaseHandle() => NativeMethods.FreeLibrary(handle);
#endregion
}
}
// eof "NativeLibraryHandle.cs"