diff --git a/CefSharp.WinForms/Internals/ParentFormMessageInterceptor.cs b/CefSharp.WinForms/Internals/ParentFormMessageInterceptor.cs
index 1dc193802..83cad20ba 100644
--- a/CefSharp.WinForms/Internals/ParentFormMessageInterceptor.cs
+++ b/CefSharp.WinForms/Internals/ParentFormMessageInterceptor.cs
@@ -6,6 +6,7 @@ using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
+using CefSharp.Internals;
namespace CefSharp.WinForms.Internals
{
@@ -149,8 +150,14 @@ namespace CefSharp.WinForms.Internals
}
case NativeMethods.WM_MOVE:
{
- x = (m.LParam.ToInt32() & 0xffff);
- y = ((m.LParam.ToInt32() >> 16) & 0xffff);
+ // Convert IntPtr into 32bit int safely without
+ // exceptions:
+ int dwLParam = m.LParam.CastToInt32();
+
+ // Extract coordinates from lo/hi word:
+ x = dwLParam & 0xffff;
+ y = (dwLParam >> 16) & 0xffff;
+
isMovingMessage = true;
break;
}
diff --git a/CefSharp/CefSharp.csproj b/CefSharp/CefSharp.csproj
index 6aab6c7e1..5a5596c94 100644
--- a/CefSharp/CefSharp.csproj
+++ b/CefSharp/CefSharp.csproj
@@ -92,6 +92,7 @@
+
diff --git a/CefSharp/Internals/IntPtrExtensions.cs b/CefSharp/Internals/IntPtrExtensions.cs
new file mode 100644
index 000000000..ab9b74837
--- /dev/null
+++ b/CefSharp/Internals/IntPtrExtensions.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace CefSharp.Internals
+{
+ public static class IntPtrExtensions
+ {
+ ///
+ /// Do an unchecked conversion from IntPtr to int
+ /// so overflow exceptions don't get thrown.
+ ///
+ ///
+ ///
+ public static int CastToInt32(this IntPtr intPtr)
+ {
+ return unchecked((int)intPtr.ToInt64());
+ }
+ }
+}