Merge pull request #920 from rassilon/issue918

Fix #918 by adding extension method to cast from IntPtr to Int32
This commit is contained in:
Bill
2015-03-31 18:57:53 -04:00
3 changed files with 31 additions and 2 deletions
@@ -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;
}
+1
View File
@@ -92,6 +92,7 @@
<Compile Include="CefFileDialogMode.cs" />
<Compile Include="DefaultResourceHandlerFactory.cs" />
<Compile Include="IJavascriptCallback.cs" />
<Compile Include="Internals\IntPtrExtensions.cs" />
<Compile Include="Internals\JavascriptCallbackProxy.cs" />
<Compile Include="Internals\JavascriptCallback.cs" />
<Compile Include="Internals\JavascriptCallbackEndpointBehavior.cs" />
+21
View File
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CefSharp.Internals
{
public static class IntPtrExtensions
{
/// <summary>
/// Do an unchecked conversion from IntPtr to int
/// so overflow exceptions don't get thrown.
/// </summary>
/// <param name="intPtr"></param>
/// <returns></returns>
public static int CastToInt32(this IntPtr intPtr)
{
return unchecked((int)intPtr.ToInt64());
}
}
}