| Author |
Message |
pandasanta
Joined: 19 Apr 2010 Posts: 3
|
Posted: Mon Apr 19, 2010 2:46 pm Post subject: SetupDiGetDeviceRegistryProperty |
|
|
I tried running the example for this method, but I get an error at this line:
string ControllerDeviceDesc = Marshal.PtrToStringAuto(ptrBuf)
I think the reason is because ptrBuf is defined as a byte[].
I am trying to invoke SetupDiGetDeviceRegistryProperty in a C# application in order to obtain the device descriptions/names from a device information set of net and modem devices. I'm not getting an error, but I'm not getting the desired result. Here is my code:
| Code: |
...
IntPtr ptrBuffer = new IntPtr();
UInt32 requiredSize;
UInt32 regType = REG_SZ (which is defined as 1);
string deviceName;
if ( SetupDiGetDeviceRegistryProperty(deviceInfoSet, ref devInfoData, SPDRP_DEVICEDESC, out regType, out ptrBuffer, BUFFER_SIZE, out requiredSize) )
{
deviceName = Marshal.PtrToStringAuto(ptrBuffer);
MessageBox.Show("Device Name = " + deviceName);
} else
{
MessageBox.Show(GetLastWin32Error());
}
... |
The code runs, but the message box only has "Device Name = ". I had originally tried using SPDRP_FRIENDLYNAME, but I got an invalid data value error, or something like that. How do I get that device name to display? Eventually, I want the device name to actually be added to a list box. But for now I just want to see it being returned properly.
Thanks! |
|
| Back to top |
|
 |
pandasanta
Joined: 19 Apr 2010 Posts: 3
|
Posted: Tue May 11, 2010 5:27 pm Post subject: SetupDiGetDeviceRegistryProperty - resolved |
|
|
I figured this out.
I changed the line:
| Code: |
| string ControllerDeviceDesc = Marshal.PtrToStringAuto(ptrBuf) |
to read:
| Code: |
| string ControllerDeviceDesc = Marshal.PtrToStringAnsi(ptrBuf) |
I also allocated the size of the ptrBuf:
| Code: |
| ptrBuf = Marshal.AllocHGlobal(BUFFER_SIZE). |
I have updated the PInvoke with this information. I hope it helps someone else!
[/code] |
|
| Back to top |
|
 |
|
|
All times are GMT + 1 Hour
|
| Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group