2014-11-05 73 views
0

我在Windows XP上運行的.Net中發現了一個錯誤。 Screen.PrimaryScreen.DeviceNameScreen.AllScreens[]的字符串值在末尾包含額外的字符(來自內存緩衝區的空值和垃圾)。這個問題在Windows 7中不存在。問題是 - Windows Update(KB)修復了這個問題嗎?Screen.PrimaryScreen.DeviceName中的無效字符

試試這個(在XP):

Text = string.Format("{0}: {1}", 
     Screen.PrimaryScreen.DeviceName.Length, 
     Screen.PrimaryScreen.DeviceName); 

通常的結果是:31: \\.\DISPLAY1。正確的長度是12而不是31.在Display1之後有\0,因此字符串看起來不錯,但是對於字符串比較它是錯誤的。

回答

0

看起來這是.Net/XP中的錯誤,它不能在Windows更新中修復。我的解決辦法是這樣的:

string dev = Screen.PrimaryScreen.DeviceName; 
int eos = dev.IndexOf('\0'); 
if (eos != -1) 
    dev = dev.Substring(0, eos);