From 9bbef90088eef4442ea21b68f79642b0628a875c Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Sun, 9 Nov 2008 11:43:02 +0000 Subject: [PATCH] Use UIntPtr instead of IntPtr to avoid overflow exceptions in x64 mode. --- Source/OpenTK/Platform/Windows/WMInput.cs | 31 +++++++++++++++-------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/Source/OpenTK/Platform/Windows/WMInput.cs b/Source/OpenTK/Platform/Windows/WMInput.cs index 53ba800b..9c34eda8 100644 --- a/Source/OpenTK/Platform/Windows/WMInput.cs +++ b/Source/OpenTK/Platform/Windows/WMInput.cs @@ -62,6 +62,13 @@ namespace OpenTK.Platform.Windows bool mouse_about_to_enter = false; protected override void WndProc(ref Message msg) { + UIntPtr lparam, wparam; + unsafe + { + lparam = (UIntPtr)(void*)msg.LParam; + wparam = (UIntPtr)(void*)msg.WParam; + } + switch ((WindowMessage)msg.Msg) { // Mouse events: @@ -70,8 +77,9 @@ namespace OpenTK.Platform.Windows break; case WindowMessage.MOUSEMOVE: - mouse.Position = new System.Drawing.Point(msg.LParam.ToInt32() & 0x0000FFFF, - (int)(msg.LParam.ToInt32() & 0xFFFF0000) >> 16); + mouse.Position = new System.Drawing.Point( + (int)(lparam.ToUInt32() & 0x0000FFFF), + (int)(lparam.ToUInt32() & 0xFFFF0000) >> 16); if (mouse_about_to_enter) { Cursor.Current = Cursors.Default; @@ -80,7 +88,7 @@ namespace OpenTK.Platform.Windows return; case WindowMessage.MOUSEWHEEL: - mouse.Wheel += (msg.WParam.ToInt32() >> 16) / 120; + mouse.Wheel += (int)(wparam.ToUInt32() >> 16) / 120; return; case WindowMessage.LBUTTONDOWN: @@ -96,7 +104,7 @@ namespace OpenTK.Platform.Windows return; case WindowMessage.XBUTTONDOWN: - mouse[((msg.WParam.ToInt32() & 0xFFFF0000) >> 16) != (int)MouseKeys.XButton1 ? MouseButton.Button1 : MouseButton.Button2] = true; + mouse[((wparam.ToUInt32() & 0xFFFF0000) >> 16) != (int)MouseKeys.XButton1 ? MouseButton.Button1 : MouseButton.Button2] = true; return; case WindowMessage.LBUTTONUP: @@ -113,7 +121,7 @@ namespace OpenTK.Platform.Windows case WindowMessage.XBUTTONUP: // TODO: Is this correct? - mouse[((msg.WParam.ToInt32() & 0xFFFF0000) >> 16) != (int)MouseKeys.XButton1 ? MouseButton.Button1 : MouseButton.Button2] = false; + mouse[((wparam.ToUInt32() & 0xFFFF0000) >> 16) != (int)MouseKeys.XButton1 ? MouseButton.Button1 : MouseButton.Button2] = false; return; // Keyboard events: @@ -132,7 +140,7 @@ namespace OpenTK.Platform.Windows // In this case, both keys will be reported as pressed. bool extended = (msg.LParam.ToInt64() & ExtendedBit) != 0; - switch ((VirtualKeys)msg.WParam) + switch ((VirtualKeys)wparam) { case VirtualKeys.SHIFT: // The behavior of this key is very strange. Unlike Control and Alt, there is no extended bit @@ -144,10 +152,13 @@ namespace OpenTK.Platform.Windows // TODO: Not 100% reliable, when both keys are pressed at once. if (ShiftRightScanCode != 0) { - if (((msg.LParam.ToInt32() >> 16) & 0xFF) == ShiftRightScanCode) - keyboard[Input.Key.ShiftRight] = pressed; - else - keyboard[Input.Key.ShiftLeft] = pressed; + unchecked + { + if (((lparam.ToUInt32() >> 16) & 0xFF) == ShiftRightScanCode) + keyboard[Input.Key.ShiftRight] = pressed; + else + keyboard[Input.Key.ShiftLeft] = pressed; + } } else {