mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-06 12:09:40 +00:00
Merge pull request #920 from rassilon/issue918
Fix #918 by adding extension method to cast from IntPtr to Int32
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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" />
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user