From a786f731542a494163ca981b1501e4f2d87cfe3f Mon Sep 17 00:00:00 2001 From: "J.D. Purcell" Date: Sat, 8 Apr 2017 18:36:29 -0400 Subject: [PATCH] Fix some places using 'int' instead of IntPtr. (#828) --- BizHawk.Client.EmuHawk/AVOut/AviWriter.cs | 25 ++++++++----------- .../CustomControls/FolderBrowserDialogEx.cs | 2 +- .../CustomControls/VirtualListView.cs | 12 ++++----- .../CustomControls/Win32.cs | 6 ++--- BizHawk.Client.EmuHawk/LogConsole.cs | 4 +-- .../tools/SNES/SNESGraphicsDebugger.cs | 4 +-- 6 files changed, 25 insertions(+), 28 deletions(-) diff --git a/BizHawk.Client.EmuHawk/AVOut/AviWriter.cs b/BizHawk.Client.EmuHawk/AVOut/AviWriter.cs index 9c046a8e0a..46dd68311f 100644 --- a/BizHawk.Client.EmuHawk/AVOut/AviWriter.cs +++ b/BizHawk.Client.EmuHawk/AVOut/AviWriter.cs @@ -360,15 +360,13 @@ namespace BizHawk.Client.EmuHawk ret.codec = Win32.decode_mmioFOURCC(opts.fccHandler); ret.Format = new byte[opts.cbFormat]; ret.Parms = new byte[opts.cbParms]; - if(opts.lpFormat != 0) Marshal.Copy(new IntPtr(opts.lpFormat), ret.Format, 0, opts.cbFormat); - if (opts.lpParms != 0) Marshal.Copy(new IntPtr(opts.lpParms), ret.Parms, 0, opts.cbParms); - + if (opts.lpFormat != IntPtr.Zero) Marshal.Copy(opts.lpFormat, ret.Format, 0, opts.cbFormat); + if (opts.lpParms != IntPtr.Zero) Marshal.Copy(opts.lpParms, ret.Parms, 0, opts.cbParms); return ret; } - [DllImport("kernel32.dll", SetLastError = true)] - public static extern bool HeapFree(IntPtr hHeap, uint dwFlags, int lpMem); + public static extern bool HeapFree(IntPtr hHeap, uint dwFlags, IntPtr lpMem); [DllImport("kernel32.dll", SetLastError = true)] public static extern IntPtr GetProcessHeap(); [DllImport("kernel32.dll", SetLastError = false)] @@ -377,25 +375,24 @@ namespace BizHawk.Client.EmuHawk public static void DeallocateAVICOMPRESSOPTIONS(ref Win32.AVICOMPRESSOPTIONS opts) { //test: increase stability by never freeing anything, ever - //if (opts.lpParms != 0) CodecToken.HeapFree(CodecToken.GetProcessHeap(), 0, opts.lpParms); - //if (opts.lpFormat != 0) CodecToken.HeapFree(CodecToken.GetProcessHeap(), 0, opts.lpFormat); - opts.lpParms = 0; - opts.lpFormat = 0; + //if (opts.lpParms != IntPtr.Zero) CodecToken.HeapFree(CodecToken.GetProcessHeap(), 0, opts.lpParms); + //if (opts.lpFormat != IntPtr.Zero) CodecToken.HeapFree(CodecToken.GetProcessHeap(), 0, opts.lpFormat); + opts.lpParms = IntPtr.Zero; + opts.lpFormat = IntPtr.Zero; } - public void AllocateToAVICOMPRESSOPTIONS(ref Win32.AVICOMPRESSOPTIONS opts) { opts = comprOptions; if (opts.cbParms != 0) { - opts.lpParms = HeapAlloc(GetProcessHeap(), 0, opts.cbParms).ToInt32(); - Marshal.Copy(Parms, 0, new IntPtr(opts.lpParms), opts.cbParms); + opts.lpParms = HeapAlloc(GetProcessHeap(), 0, opts.cbParms); + Marshal.Copy(Parms, 0, opts.lpParms, opts.cbParms); } if (opts.cbFormat != 0) { - opts.lpFormat = HeapAlloc(GetProcessHeap(), 0, opts.cbFormat).ToInt32(); - Marshal.Copy(Format, 0, new IntPtr(opts.lpFormat), opts.cbFormat); + opts.lpFormat = HeapAlloc(GetProcessHeap(), 0, opts.cbFormat); + Marshal.Copy(Format, 0, opts.lpFormat, opts.cbFormat); } } diff --git a/BizHawk.Client.EmuHawk/CustomControls/FolderBrowserDialogEx.cs b/BizHawk.Client.EmuHawk/CustomControls/FolderBrowserDialogEx.cs index 37fd03d037..31364d04f5 100644 --- a/BizHawk.Client.EmuHawk/CustomControls/FolderBrowserDialogEx.cs +++ b/BizHawk.Client.EmuHawk/CustomControls/FolderBrowserDialogEx.cs @@ -77,7 +77,7 @@ namespace BizHawk.Client.EmuHawk case 1: { IntPtr str = Marshal.StringToHGlobalUni(SelectedPath); - Win32.SendMessage(hwnd, (0x400 + 103), 1, str.ToInt32()); + Win32.SendMessage(hwnd, (0x400 + 103), (IntPtr)1, str); Marshal.FreeHGlobal(str); break; } diff --git a/BizHawk.Client.EmuHawk/CustomControls/VirtualListView.cs b/BizHawk.Client.EmuHawk/CustomControls/VirtualListView.cs index 1d5afdc01e..0ae416b548 100644 --- a/BizHawk.Client.EmuHawk/CustomControls/VirtualListView.cs +++ b/BizHawk.Client.EmuHawk/CustomControls/VirtualListView.cs @@ -499,8 +499,8 @@ namespace BizHawk.Client.EmuHawk Win32.SendMessage( this.Handle, (int)ListViewMessages.LVM_SETITEMSTATE, - index, - ptrItem.ToInt32()); + (IntPtr)index, + ptrItem); } catch (Exception ex) { @@ -524,8 +524,8 @@ namespace BizHawk.Client.EmuHawk Win32.SendMessage( this.Handle, (int)ListViewMessages.LVM_SETITEMCOUNT, - this._itemCount, - 0); + (IntPtr)this._itemCount, + IntPtr.Zero); } protected void OnDispInfoNotice(ref Message m, bool useAnsi) @@ -749,14 +749,14 @@ namespace BizHawk.Client.EmuHawk lvhti.Point.X = x; lvhti.Point.Y = y; Marshal.StructureToPtr(lvhti, ptrlvhti, true); - int z = Win32.SendMessage(this.Handle, (int)ListViewMessages.LVM_HITTEST, 0, ptrlvhti.ToInt32()); + int z = (int)Win32.SendMessage(this.Handle, (int)ListViewMessages.LVM_HITTEST, (IntPtr)0, ptrlvhti); Marshal.PtrToStructure(ptrlvhti, lvhti); return z; } public void ensureVisible(int index) { - Win32.SendMessage(Handle, (int)ListViewMessages.LVM_ENSUREVISIBLE, index, 1); + Win32.SendMessage(Handle, (int)ListViewMessages.LVM_ENSUREVISIBLE, (IntPtr)index, (IntPtr)1); } public void ensureVisible() diff --git a/BizHawk.Client.EmuHawk/CustomControls/Win32.cs b/BizHawk.Client.EmuHawk/CustomControls/Win32.cs index 9e734d75eb..154d462ba8 100644 --- a/BizHawk.Client.EmuHawk/CustomControls/Win32.cs +++ b/BizHawk.Client.EmuHawk/CustomControls/Win32.cs @@ -311,9 +311,9 @@ namespace BizHawk.Client.EmuHawk public int dwQuality; public int dwBytesPerSecond; public int dwFlags; - public int lpFormat; + public IntPtr lpFormat; public int cbFormat; - public int lpParms; + public IntPtr lpParms; public int cbParms; public int dwInterleaveEvery; } @@ -472,7 +472,7 @@ namespace BizHawk.Client.EmuHawk } [DllImport("user32.dll", CharSet = CharSet.Auto)] - public static extern int SendMessage(IntPtr hWnd, int msg, int wParam, int lParam); + public static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam); [DllImport("Kernel32.dll", EntryPoint = "RtlZeroMemory", SetLastError = false)] public static extern void ZeroMemory(IntPtr dest, uint size); diff --git a/BizHawk.Client.EmuHawk/LogConsole.cs b/BizHawk.Client.EmuHawk/LogConsole.cs index 20d8ac00e6..f4930076a3 100644 --- a/BizHawk.Client.EmuHawk/LogConsole.cs +++ b/BizHawk.Client.EmuHawk/LogConsole.cs @@ -159,8 +159,8 @@ namespace BizHawk.Client.EmuHawk if (Win32.AllocConsole()) { //set icons for the console so we can tell them apart from the main window - Win32.SendMessage(Win32.GetConsoleWindow(), 0x0080/*WM_SETICON*/, 0/*ICON_SMALL*/, Properties.Resources.console16x16.GetHicon().ToInt32()); - Win32.SendMessage(Win32.GetConsoleWindow(), 0x0080/*WM_SETICON*/, 1/*ICON_LARGE*/, Properties.Resources.console32x32.GetHicon().ToInt32()); + Win32.SendMessage(Win32.GetConsoleWindow(), 0x0080/*WM_SETICON*/, (IntPtr)0/*ICON_SMALL*/, Properties.Resources.console16x16.GetHicon()); + Win32.SendMessage(Win32.GetConsoleWindow(), 0x0080/*WM_SETICON*/, (IntPtr)1/*ICON_LARGE*/, Properties.Resources.console32x32.GetHicon()); hasConsole = true; } else diff --git a/BizHawk.Client.EmuHawk/tools/SNES/SNESGraphicsDebugger.cs b/BizHawk.Client.EmuHawk/tools/SNES/SNESGraphicsDebugger.cs index aae602d2a3..fec6b27edf 100644 --- a/BizHawk.Client.EmuHawk/tools/SNES/SNESGraphicsDebugger.cs +++ b/BizHawk.Client.EmuHawk/tools/SNES/SNESGraphicsDebugger.cs @@ -892,7 +892,7 @@ namespace BizHawk.Client.EmuHawk { groupFreeze.SuspendLayout(); - Win32.SendMessage(groupFreeze.Handle, 11, 0, 0); //WM_SETREDRAW false + Win32.SendMessage(groupFreeze.Handle, 11, (IntPtr)0, IntPtr.Zero); //WM_SETREDRAW false var tp = tabctrlDetails.SelectedTab; @@ -912,7 +912,7 @@ namespace BizHawk.Client.EmuHawk groupFreeze.ResumeLayout(); - Win32.SendMessage(groupFreeze.Handle, 11, 1, 0); //WM_SETREDRAW true + Win32.SendMessage(groupFreeze.Handle, 11, (IntPtr)1, IntPtr.Zero); //WM_SETREDRAW true groupFreeze.Refresh(); }