最近看别人写的一个控件TerminalControl,在WINXP下使用没有问题,但在win7x64用C#调试时,会出现溢出错误。
主要的语句如下:
public void KeyDown (System.Windows.Forms.Message KeyMess)
{
System.Byte[] lBytes;
System.Byte[] wBytes;
System.UInt16 KeyValue = 0;
System.UInt16 RepeatCount = 0;
System.Byte ScanCode = 0;
System.Byte AnsiChar = 0;
System.UInt16 UniChar = 0;
System.Byte Flags = 0;
lBytes = System.BitConverter.GetBytes (KeyMess.LParam.ToInt32 ());//这句会出现OverflowException
wBytes = System.BitConverter.GetBytes (KeyMess.WParam.ToInt32 ());
C#调试时会出现“算术运算导致溢出”的提示,虽然修改后
try
{
lBytes = System.BitConverter.GetBytes(KeyMess.LParam.ToInt32());
wBytes = System.BitConverter.GetBytes(KeyMess.WParam.ToInt32());
}
catch (System.Exception CurException)
{
//System.Console.WriteLine ("Connect: " + CurException.Message);
MessageBox.Show("Try:" +CurException.Message);
return;
}
编译是没有问题,但运行时仍然报“算术运算导致溢出”的提示。应该是KeyMess.LParam.ToInt32()操作时就有溢出的问题,请高人解答一下看有什么好的方法解决。谢谢。