using System; namespace ScreenConnect; public abstract class DiskNativeLibrary : CriticalFinalizerDisposableObject, INativeLibrary { private IntPtr libraryHandle; protected DiskNativeLibrary(string libraryPath) { libraryHandle = TryLoadNativeLibrary(libraryPath); if (libraryHandle == IntPtr.Zero) { throw new InvalidOperationException("Unable to load native library from '" + libraryPath + "'"); } } public IntPtr TryGetProcedureAddress(string procedureName) { procedureName.AssertArgumentNonNull("procedureName"); return TryGetProcedureAddress(libraryHandle, procedureName); } protected override void Dispose(bool disposing) { if (libraryHandle != IntPtr.Zero) { TryFreeNativeLibrary(libraryHandle); } } protected abstract IntPtr TryLoadNativeLibrary(string libraryPath); protected abstract void TryFreeNativeLibrary(IntPtr libraryHandle); protected abstract IntPtr TryGetProcedureAddress(IntPtr libraryHandle, string procedureName); }