private void GetPropertiesSPDRP(SafeHandle usbHandle) { byte[] propBuffer = new byte[1024]; GCHandle gcPropBuffer = GCHandle.Alloc(propBuffer, GCHandleType.Pinned); LibUsbRequest req = new LibUsbRequest(); Dictionary <string, int> allProps = LHelper.GetEnumData(typeof(DevicePropertyType)); foreach (KeyValuePair <string, int> prop in allProps) { object oValue = String.Empty; req.DeviceProperty.ID = prop.Value; int iReturnBytes; bool bSuccess = LibUsbDriverIO.UsbIOSync(usbHandle, LibUsbIoCtl.GET_REG_PROPERTY, req, LibUsbRequest.Size, gcPropBuffer.AddrOfPinnedObject(), propBuffer.Length, out iReturnBytes); if (bSuccess) { switch ((DevicePropertyType)prop.Value) { case DevicePropertyType.PhysicalDeviceObjectName: case DevicePropertyType.LocationInformation: case DevicePropertyType.Class: case DevicePropertyType.Mfg: case DevicePropertyType.DeviceDesc: case DevicePropertyType.Driver: case DevicePropertyType.EnumeratorName: case DevicePropertyType.FriendlyName: case DevicePropertyType.ClassGuid: oValue = GetAsString(propBuffer, iReturnBytes); break; case DevicePropertyType.HardwareId: case DevicePropertyType.CompatibleIds: oValue = GetAsStringArray(propBuffer, iReturnBytes); break; case DevicePropertyType.BusNumber: case DevicePropertyType.InstallState: case DevicePropertyType.LegacyBusType: case DevicePropertyType.RemovalPolicy: case DevicePropertyType.UiNumber: case DevicePropertyType.Address: oValue = GetAsStringInt32(propBuffer, iReturnBytes); break; case DevicePropertyType.BusTypeGuid: oValue = GetAsGuid(propBuffer, iReturnBytes); break; } } else { oValue = String.Empty; } mDeviceProperties.Add(prop.Key, oValue); } gcPropBuffer.Free(); }
public static void getSPDRPProperties(IntPtr deviceInfoSet, ref SP_DEVINFO_DATA deviceInfoData, Dictionary <string, object> deviceProperties) { byte[] propBuffer = new byte[1024]; Dictionary <string, int> allProps = LHelper.GetEnumData(typeof(SPDRP)); foreach (KeyValuePair <string, int> prop in allProps) { object oValue = String.Empty; int iReturnBytes; RegistryValueKind regPropType; bool bSuccess = SetupDiGetDeviceRegistryProperty(deviceInfoSet, ref deviceInfoData, (SPDRP)prop.Value, out regPropType, propBuffer, propBuffer.Length, out iReturnBytes); if (bSuccess) { switch ((SPDRP)prop.Value) { case SPDRP.PhysicalDeviceObjectName: case SPDRP.LocationInformation: case SPDRP.Class: case SPDRP.Mfg: case SPDRP.DeviceDesc: case SPDRP.Driver: case SPDRP.EnumeratorName: case SPDRP.FriendlyName: case SPDRP.ClassGuid: oValue = UsbRegistry.GetAsString(propBuffer, iReturnBytes); break; case SPDRP.HardwareId: case SPDRP.CompatibleIds: case SPDRP.LocationPaths: oValue = UsbRegistry.GetAsStringArray(propBuffer, iReturnBytes); break; case SPDRP.BusNumber: case SPDRP.InstallState: case SPDRP.LegacyBusType: case SPDRP.RemovalPolicy: case SPDRP.UiNumber: case SPDRP.Address: oValue = UsbRegistry.GetAsStringInt32(propBuffer, iReturnBytes); break; case SPDRP.BusTypeGuid: oValue = UsbRegistry.GetAsGuid(propBuffer, iReturnBytes); break; } } else { oValue = String.Empty; } deviceProperties.Add(prop.Key, oValue); } }