LoadLibrary() private method

private LoadLibrary ( string dllName ) : IntPtr
dllName string
return IntPtr
Esempio n. 1
0
            internal XInput()
            {
                // Try to load the newest XInput***.dll installed on the system
                // The delegates below will be loaded dynamically from that dll
                dll = Functions.LoadLibrary("XINPUT1_4");
                if (dll == IntPtr.Zero)
                {
                    dll = Functions.LoadLibrary("XINPUT1_3");
                }
                if (dll == IntPtr.Zero)
                {
                    dll = Functions.LoadLibrary("XINPUT1_2");
                }
                if (dll == IntPtr.Zero)
                {
                    dll = Functions.LoadLibrary("XINPUT1_1");
                }
                if (dll == IntPtr.Zero)
                {
                    dll = Functions.LoadLibrary("XINPUT9_1_0");
                }
                if (dll == IntPtr.Zero)
                {
                    throw new NotSupportedException("XInput was not found on this platform");
                }

                // Load the entry points we are interested in from that dll
                GetCapabilities = (XInputGetCapabilities)Load("XInputGetCapabilities", typeof(XInputGetCapabilities));
                GetState        =
                    // undocumented XInputGetStateEx with support for the "Guide" button (requires XINPUT_1_3+)
                    (XInputGetState)Load("XInputGetStateEx", typeof(XInputGetState)) ??
                    // documented XInputGetState (no support for the "Guide" button)
                    (XInputGetState)Load("XInputGetState", typeof(XInputGetState));
                SetState = (XInputSetState)Load("XInputSetState", typeof(XInputSetState));
            }
Esempio n. 2
0
 private static void LoadOpenGL()
 {
     OpenGLHandle = Functions.LoadLibrary(OpenGLName);
     if (OpenGLHandle == IntPtr.Zero)
     {
         throw new ApplicationException(String.Format("LoadLibrary(\"{0}\") call failed with code {1}",
                                                      OpenGLName, Marshal.GetLastWin32Error()));
     }
     Debug.WriteLine(String.Format("Loaded opengl32.dll: {0}", OpenGLHandle));
 }
Esempio n. 3
0
 static WinGLContext()
 {
     // Dynamically load the OpenGL32.dll in order to use the extension loading capabilities of Wgl.
     if (opengl32Handle == IntPtr.Zero)
     {
         opengl32Handle = Functions.LoadLibrary(opengl32Name);
         if (opengl32Handle == IntPtr.Zero)
         {
             throw new ApplicationException(String.Format("LoadLibrary(\"{0}\") call failed with code {1}",
                                                          opengl32Name, Marshal.GetLastWin32Error()));
         }
         Debug.WriteLine(String.Format("Loaded opengl32.dll: {0}", opengl32Handle));
     }
 }
Esempio n. 4
0
 internal static void Init()
 {
     lock (WinGLContext.SyncRoot)
     {
         if (!(WinGLContext.opengl32Handle == IntPtr.Zero))
         {
             return;
         }
         WinGLContext.opengl32Handle = Functions.LoadLibrary("OPENGL32.DLL");
         if (WinGLContext.opengl32Handle == IntPtr.Zero)
         {
             throw new ApplicationException(string.Format("LoadLibrary(\"{0}\") call failed with code {1}", (object)"OPENGL32.DLL", (object)Marshal.GetLastWin32Error()));
         }
     }
 }
        static WinGLContext()
        {
            lock (LoadLock)
            {
                // Dynamically load opengl32.dll in order to use the extension loading capabilities of Wgl.
                if (opengl32Handle == IntPtr.Zero)
                {
                    opengl32Handle = Functions.LoadLibrary(opengl32Name);
                    if (opengl32Handle == IntPtr.Zero)
                    {
                        throw new ApplicationException(String.Format("LoadLibrary(\"{0}\") call failed with code {1}",
                                                                     opengl32Name, Marshal.GetLastWin32Error()));
                    }
                    Debug.WriteLine(String.Format("Loaded opengl32.dll: {0}", opengl32Handle));
                }

                // We need to create a temp context in order to load
                // wgl extensions (e.g. for multisampling or GL3).
                // We cannot rely on OpenTK.Platform.Wgl until we
                // create the context and call Wgl.LoadAll().
                Debug.Print("Creating temporary context for wgl extensions.");
                using (INativeWindow native = new NativeWindow())
                {
                    // Create temporary context and load WGL entry points
                    // First, set a compatible pixel format to the device context
                    // of the temp window
                    WinWindowInfo   window   = native.WindowInfo as WinWindowInfo;
                    WinGraphicsMode selector = new WinGraphicsMode(window.DeviceContext);
                    SetGraphicsModePFD(selector, GraphicsMode.Default, window);

                    // Then, construct a temporary context and load all wgl extensions
                    ContextHandle temp_context = new ContextHandle(Wgl.Imports.CreateContext(window.DeviceContext));
                    if (temp_context != ContextHandle.Zero)
                    {
                        // Make the context current.
                        // Note: on some video cards and on some virtual machines, wglMakeCurrent
                        // may fail with an errorcode of 6 (INVALID_HANDLE). The suggested workaround
                        // is to call wglMakeCurrent in a loop until it succeeds.
                        // See https://www.opengl.org/discussion_boards/showthread.php/171058-nVidia-wglMakeCurrent()-multiple-threads
                        // Sigh...
                        for (int retry = 0; retry < 5; retry++)
                        {
                            bool success = Wgl.Imports.MakeCurrent(window.DeviceContext, temp_context.Handle);
                            if (!success)
                            {
                                Debug.Print("wglMakeCurrent failed with error: {0}. Retrying", Marshal.GetLastWin32Error());
                                System.Threading.Thread.Sleep(10);
                            }
                            else
                            {
                                // wglMakeCurrent succeeded, we are done here!
                                break;
                            }
                        }

                        // Load wgl extensions and destroy temporary context
                        Wgl.LoadAll();
                        Wgl.Imports.MakeCurrent(IntPtr.Zero, IntPtr.Zero);
                        Wgl.Imports.DeleteContext(temp_context.Handle);
                    }
                    else
                    {
                        Debug.Print("wglCreateContext failed with error: {0}", Marshal.GetLastWin32Error());
                    }
                }
            }
        }