I have a bit of a weird problem.
I have a form with a Label in it for outputting text at certain points in the program instead of console output.
Given the following code:
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";
}
I get just the one hardware ID output on the label. This piece of code is at the end of my loop. at 1st this made me think that my loop was some how hanging, but when I decided to direct output to a file I get almost what I want and the output outside the loop.
Can anyone tell me what’s going on here?
All I want is to get the string representing the hardware ID from the []byte (ptrBuf).
Can some explain what’s going on here, please?
My working environment is MSVstudio 2008 express. In windows 7.
Thanks
You haven’t shown what
tCodeis, unfortunately.Looking at the docs for the API call it looks like it should be populated with a REG_SZ. I suspect that’s Unicode, i.e.
should convert it.
However, if you’re expecting multiple values, I wonder if it’s a
'\0'-separated string: trying to output that in a Win32 control will indeed stop at the first'\0'.Try this:
That should (if I’m guessing correctly) space-separate the values.