XInputGetStateEx obtained through ordinal
authorSebastien Pellizzari <sebastien.pellizzari@gmail.com>
Tue, 14 Feb 2017 08:17:41 +0000 (09:17 +0100)
committerSebastien Pellizzari <sebastien.pellizzari@gmail.com>
Tue, 14 Feb 2017 08:17:41 +0000 (09:17 +0100)
src/OpenTK/Platform/Windows/XInputJoystick.cs

index 6b718de..357bfd2 100644 (file)
@@ -371,8 +371,8 @@ namespace OpenTK.Platform.Windows
                 // 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)) ??
+                    // undocumented XInputGetStateEx (Ordinal 100) with support for the "Guide" button (requires XINPUT_1_3+)
+                    (XInputGetState)Load(100, typeof(XInputGetState)) ??
                     // documented XInputGetState (no support for the "Guide" button)
                     (XInputGetState)Load("XInputGetState", typeof(XInputGetState));
                 SetState = (XInputSetState)Load("XInputSetState", typeof(XInputSetState));
@@ -380,6 +380,14 @@ namespace OpenTK.Platform.Windows
 
             #region Private Members
 
+            Delegate Load(ushort ordinal, Type type)
+            {
+                IntPtr pfunc = Functions.GetProcAddress(dll, (IntPtr)ordinal);
+                if (pfunc != IntPtr.Zero)
+                    return Marshal.GetDelegateForFunctionPointer(pfunc, type);
+                return null;
+            }
+
             Delegate Load(string name, Type type)
             {
                 IntPtr pfunc = Functions.GetProcAddress(dll, name);