From 69f2d6c94c045dcfc42b970bbe4758ead3efa9e7 Mon Sep 17 00:00:00 2001 From: Christian Grasser Date: Sat, 5 Nov 2016 01:25:53 +0100 Subject: [PATCH] fix for issue X64 pointer arithmetic issue #18 --- .../NppPluginNETHelper.cs | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Visual Studio Project Template C#/PluginInfrastructure/NppPluginNETHelper.cs b/Visual Studio Project Template C#/PluginInfrastructure/NppPluginNETHelper.cs index abe0d42..c5517df 100644 --- a/Visual Studio Project Template C#/PluginInfrastructure/NppPluginNETHelper.cs +++ b/Visual Studio Project Template C#/PluginInfrastructure/NppPluginNETHelper.cs @@ -74,17 +74,17 @@ public void Add(FuncItem funcItem) RtlMoveMemory(newPointer, _nativePointer, oldSize); Marshal.FreeHGlobal(_nativePointer); } - IntPtr ptrPosNewItem = (IntPtr)((int)newPointer + oldSize); + IntPtr ptrPosNewItem = (IntPtr)(newPointer.ToInt64() + oldSize); byte[] aB = Encoding.Unicode.GetBytes(funcItem._itemName + "\0"); Marshal.Copy(aB, 0, ptrPosNewItem, aB.Length); - ptrPosNewItem = (IntPtr)((int)ptrPosNewItem + 128); + ptrPosNewItem = (IntPtr)(ptrPosNewItem.ToInt64() + 128); IntPtr p = (funcItem._pFunc != null) ? Marshal.GetFunctionPointerForDelegate(funcItem._pFunc) : IntPtr.Zero; Marshal.WriteIntPtr(ptrPosNewItem, p); - ptrPosNewItem = (IntPtr)((int)ptrPosNewItem + IntPtr.Size); + ptrPosNewItem = (IntPtr)(ptrPosNewItem.ToInt64() + IntPtr.Size); Marshal.WriteInt32(ptrPosNewItem, funcItem._cmdID); - ptrPosNewItem = (IntPtr)((int)ptrPosNewItem + 4); + ptrPosNewItem = (IntPtr)(ptrPosNewItem.ToInt64() + 4); Marshal.WriteInt32(ptrPosNewItem, Convert.ToInt32(funcItem._init2Check)); - ptrPosNewItem = (IntPtr)((int)ptrPosNewItem + 4); + ptrPosNewItem = (IntPtr)(ptrPosNewItem.ToInt64() + 4); if (funcItem._pShKey._key != 0) { IntPtr newShortCutKey = Marshal.AllocHGlobal(4); @@ -103,15 +103,15 @@ public void RefreshItems() { FuncItem updatedItem = new FuncItem(); updatedItem._itemName = _funcItems[i]._itemName; - ptrPosItem = (IntPtr)((int)ptrPosItem + 128); + ptrPosItem = (IntPtr)(ptrPosItem.ToInt64() + 128); updatedItem._pFunc = _funcItems[i]._pFunc; - ptrPosItem = (IntPtr)((int)ptrPosItem + IntPtr.Size); + ptrPosItem = (IntPtr)(ptrPosItem.ToInt64() + IntPtr.Size); updatedItem._cmdID = Marshal.ReadInt32(ptrPosItem); - ptrPosItem = (IntPtr)((int)ptrPosItem + 4); + ptrPosItem = (IntPtr)(ptrPosItem.ToInt64() + 4); updatedItem._init2Check = _funcItems[i]._init2Check; - ptrPosItem = (IntPtr)((int)ptrPosItem + 4); + ptrPosItem = (IntPtr)(ptrPosItem.ToInt64() + 4); updatedItem._pShKey = _funcItems[i]._pShKey; - ptrPosItem = (IntPtr)((int)ptrPosItem + IntPtr.Size); + ptrPosItem = (IntPtr)(ptrPosItem.ToInt64() + IntPtr.Size); _funcItems[i] = updatedItem; }