public static NativeLibraryInterface <IOpenGl> Load()
        {
            var libraryHandle = NativeLibrary.Load("opengl32");

            if (libraryHandle.IsInvalid())
            {
                throw new Exception("Unable to load opengl32.");
            }

            try
            {
                var wglGetProcAddressPtr = NativeLibrary.GetExport(libraryHandle, "wglGetProcAddress");

                if (wglGetProcAddressPtr.IsInvalid())
                {
                    throw new Exception("You are not loading OpenGL today.");
                }

                var wglGetProcAddress = Marshal.GetDelegateForFunctionPointer <ModuleLoader>(wglGetProcAddressPtr);

                return(NativeLibraryInterface.Create <IOpenGl>(
                           "OpenGl",
                           libraryHandle,
                           mn => "gl" + mn,
                           (handle, name) => GetGlProcAddress(wglGetProcAddress, handle, name)));
            }
            catch
            {
                NativeLibrary.Free(libraryHandle);
                throw;
            }
        }
示例#2
0
 public static IServiceCollection AddSqlite3(
     this IServiceCollection services,
     string dll)
 {
     return(services.AddNativeLibrary <ISqlite3>(
                _ => NativeLibraryInterface.Create <ISqlite3>(dll, ResolveName)));
 }