少し奇妙な問題があります。コンソール出力ではなく、プログラムの特定の時点でテキストを出力するためのラベルを含むフォームがあります。次のコードがあるとします。
result = SetupDiGetDeviceRegistryProperty(deviceInfoSet, ref tBuff,
(uint)SPDRP.DEVICEDESC,
out RegType, ptrBuf,
buffersize, out RequiredSize);
if (!result)
{
errorMessage = new Win32Exception(Marshal.GetLastWin32Error()).Message;
statusLabel.Text += "\nSetupDiGetDeviceRegistryProperty failed because "
+ errorMessage.ToString();
}
else
{
statusLabel.Text += "\nPtr buffer length is: " + ptrBuf.Length.ToString();
sw.WriteLine(tCode.GetString(ptrBuf) );
sw.WriteLine("\n");
// This is the only encoding that will give any legible output.
// Others only show the first character "U"
string tmp = tCode.GetString(ptrBuf) + "\n";
statusLabel.Text += "\nDevice is: " + tmp + ".\n";
}
ラベルにハードウェア ID 出力が 1 つだけ表示されます。このコードはループの最後にあります。最初は、これにより、ループがいくらかハングしていると思いましたが、出力をファイルに送信することにしたとき、ほとんど必要なものと出力がループ外に得られました。ここで何が起こっているのか誰か教えてもらえますか? [] バイト ( ptrBuf )からハードウェア ID を表す文字列を取得するだけです。ここで何が起こっているのか説明してもらえますか? 私の作業環境は MSVstudio 2008 Express です。ウィンドウズ7で.
ありがとう