我们的应用程序中有以下 C# 代码:
private IntPtr _DefaultWndProc = IntPtr.Zero;
[DllImport("user32")]
private static extern IntPtr SetWindowLongPtr(IntPtr hwnd, int index,
WndProcPointer wndProcPointer);
[DllImport("user32")]
private static extern IntPtr SetWindowLongPtr(IntPtr hwnd, int index,
IntPtr wndProc);
[DllImport("user32")]
private static extern IntPtr GetWindowLongPtr(IntPtr hwnd, int index);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
private static extern int CallWindowProc(IntPtr wndProc, IntPtr hwnd, int msg,
IntPtr wparam, IntPtr lparam);
private const int GWL_WNDPROC = (-4);
private const int WM_NCDESTROY = 0x0082;
private delegate int WndProcPointer(IntPtr hwnd, nt msg,
IntPtr wparam, IntPtr lparam);
protected virtual int WndProc(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam)
{
return CallWindowProc(_DefaultWndProc, hwnd, msg, wparam, lparam);
}
_DefaultWndProc
设置如下:
_DefaultWndProc = SetWindowLongPtr(control.Handle, GWL_WNDPROC, _MyWndProc);
当我们为 32 位配置编译并执行该程序时,一切正常。
但是,如果我们将配置设置为 64 位,上面列出的方法调用CallWindowProc(_DefaultWndProc, hwnd, msg, wparam, lparam)
会抛出以下异常:
System.OverflowException - {"Arithmetic operation resulted in an overflow."}
仅当我们将鼠标光标移到ListView
.
任何想法 ?