Overflow Errors in 64-bit Windows Server 2012 after Upgrade to .NET Framework?

我怕爱的太早我们不能终老 提交于 2019-12-12 01:52:22

问题


Our solution was recently upgraded from .NET Framework v3.5 to v4.5.2 and as a result we have had some overflow errors running on Windows Server 2012 64-bit machines.

These overflow errors seem to be coming from any instance where we call this function from the Windows API:

[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, IntPtr lParam);

The overflow was happening because for lParam in some instances, for whatever reason, it was being passed an int instead of an IntPtr even though the function expects an IntPtr.

What was interesting was these issues only manifested after upgrading .NET and ONLY on Windows Server 2012 64-bit machines.

I'm trying to decipher the cause for this only happening under these circumstances, and also trying to find an effective way to find where other instances of this kind of overflow error could occur.

My first thought was to look for all instances where SendMessage was being called, but this could miss some other instances where IntPtr is being misused. My other idea was to use either ReSharper or FXCop to detect these sort of instances and alert me to them, but I don't know how or if this is possible and by default ReSharper isn't giving any complaints.


回答1:


You should use IntPtr instead of int because the last two arguments of the SendMessage function are pointers. See Windows Data Types about WPARAM and LPARAM types.

[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);


来源:https://stackoverflow.com/questions/28880570/overflow-errors-in-64-bit-windows-server-2012-after-upgrade-to-net-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!