Use Marshal.GetLastWin32Error instead of GetLastError.
authorFraser Waters <frassle@gmail.com>
Sun, 23 Mar 2014 22:31:32 +0000 (22:31 +0000)
committerFraser Waters <frassle@gmail.com>
Sun, 23 Mar 2014 22:31:32 +0000 (22:31 +0000)
Also removes magic number 1171 and replaces with constant.

Source/OpenTK/Platform/Windows/API.cs
Source/OpenTK/Platform/Windows/WinGLNative.cs

index a29c677..d73025b 100644 (file)
@@ -111,13 +111,6 @@ namespace OpenTK.Platform.Windows
 
     internal static class Functions
     {
-        #region GetLastError
-
-        [DllImport("Kernel32.dll")]
-        internal static extern uint GetLastError();
-
-        #endregion
-
         #region Window functions
 
         #region SetWindowPos
@@ -1680,6 +1673,14 @@ namespace OpenTK.Platform.Windows
 
             internal static readonly IntPtr HKEY_LOCAL_MACHINE = new IntPtr(unchecked((int)0x80000002));
 
+            // System Error Codes
+            // http://msdn.microsoft.com/en-us/library/windows/desktop/ms681381(v=vs.85).aspx
+
+            /// <summary>
+            /// The point passed to GetMouseMovePoints is not in the buffer.
+            /// </summary>
+            internal const int ERROR_POINT_NOT_FOUND = 1171;
+
             /// <summary>
             /// Retrieves the points using the display resolution.
             /// </summary>
index 5bfd209..eecfedb 100644 (file)
@@ -435,17 +435,17 @@ namespace OpenTK.Platform.Windows
                     &movePoint, movePoints, numPoints,
                     Constants.GMMP_USE_DISPLAY_POINTS);
 
-                uint lastError = Functions.GetLastError();
+                int lastError = Marshal.GetLastWin32Error();
 
                 // No points returned or search point not found
-                if (points == 0 || (points == -1 && lastError == 1171))
+                if (points == 0 || (points == -1 && lastError == Constants.ERROR_POINT_NOT_FOUND))
                 {
                     // Just use the mouse move position
                     mouse.Position = point;
                 }
                 else if (points == -1)
                 {
-                    throw new System.ComponentModel.Win32Exception((int)lastError);
+                    throw new System.ComponentModel.Win32Exception(lastError);
                 }
                 else
                 {