From fbe6cc0a314db3b8d4a378760d5706f0b2a7d5f3 Mon Sep 17 00:00:00 2001 From: Fraser Waters Date: Sun, 23 Mar 2014 22:31:32 +0000 Subject: [PATCH] Use Marshal.GetLastWin32Error instead of GetLastError. Also removes magic number 1171 and replaces with constant. --- Source/OpenTK/Platform/Windows/API.cs | 15 ++++++++------- Source/OpenTK/Platform/Windows/WinGLNative.cs | 6 +++--- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Source/OpenTK/Platform/Windows/API.cs b/Source/OpenTK/Platform/Windows/API.cs index a29c677f..d73025b6 100644 --- a/Source/OpenTK/Platform/Windows/API.cs +++ b/Source/OpenTK/Platform/Windows/API.cs @@ -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 + + /// + /// The point passed to GetMouseMovePoints is not in the buffer. + /// + internal const int ERROR_POINT_NOT_FOUND = 1171; + /// /// Retrieves the points using the display resolution. /// diff --git a/Source/OpenTK/Platform/Windows/WinGLNative.cs b/Source/OpenTK/Platform/Windows/WinGLNative.cs index 5bfd209d..eecfedb4 100644 --- a/Source/OpenTK/Platform/Windows/WinGLNative.cs +++ b/Source/OpenTK/Platform/Windows/WinGLNative.cs @@ -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 {