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: Select all
IntPtr ptrBuffer = new IntPtr();
UInt32 regType = REG_SZ (which is defined as 1);
if ( SetupDiGetDeviceRegistryProperty(deviceInfoSet, ref devInfoData, SPDRP_DEVICEDESC, out regType, out ptrBuffer, BUFFER_SIZE, out requiredSize) )
deviceName = Marshal.PtrToStringAuto(ptrBuffer);
MessageBox.Show("Device Name = " + deviceName);
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.