internal static string GetDeviceInterfaceName(Guid class_guid) { DeviceProperty prop = GetProperty(class_guid, true, DevicePropertyKeys.DEVPKEY_DeviceInterfaceClass_Name); if (prop?.Type == DEVPROPTYPE.STRING) { return(prop.GetString()); } prop = GetProperty(class_guid, true, DevicePropertyKeys.DEVPKEY_NAME); if (prop?.Type == DEVPROPTYPE.STRING) { return(prop.GetString()); } return(DeviceInterfaceClassGuids.GuidToName(class_guid)); }
internal static string GetDeviceName(int devinst) { DeviceProperty prop = GetProperty(devinst, DevicePropertyKeys.DEVPKEY_Device_FriendlyName); if (prop?.Type == DEVPROPTYPE.STRING) { return(prop.GetString()); } prop = GetProperty(devinst, DevicePropertyKeys.DEVPKEY_NAME); if (prop?.Type == DEVPROPTYPE.STRING) { return(prop.GetString()); } return(GetProperty(devinst, DevicePropertyKeys.DEVPKEY_Device_DeviceDesc)?.GetString() ?? string.Empty); }
internal static DeviceProperty GetProperty(string link_path, DEVPROPKEY key) { DeviceProperty ret = new DeviceProperty() { Name = DevicePropertyKeys.KeyToName(key), FmtId = key.fmtid, Pid = key.pid, Data = new byte[0] }; using (var buffer = GetDeviceInterfaceProperty(link_path, key, out DEVPROPTYPE type, false).GetResultOrDefault()) { if (buffer != null) { ret.Type = type; ret.Data = buffer.ToArray(); } } return(ret); }
internal static DeviceProperty GetProperty(int devinst, DEVPROPKEY key) { DeviceProperty ret = new DeviceProperty() { Name = DevicePropertyKeys.KeyToName(key), FmtId = key.fmtid, Pid = key.pid, Data = new byte[0] }; using (var buffer = new SafeHGlobalBuffer(2000)) { int length = buffer.Length; if (DeviceNativeMethods.CM_Get_DevNode_PropertyW(devinst, key, out DEVPROPTYPE type, buffer, ref length, 0) == CrError.SUCCESS) { ret.Type = type; ret.Data = buffer.ReadBytes(length); } } return(ret); }
internal static DeviceProperty GetProperty(Guid class_guid, bool interface_guid, DEVPROPKEY key) { DeviceProperty ret = new DeviceProperty() { Name = DevicePropertyKeys.KeyToName(key), FmtId = key.fmtid, Pid = key.pid, Data = new byte[0] }; using (var buffer = GetClassProperty(class_guid, interface_guid ? CmClassType.Interface : CmClassType.Installer, key, out DEVPROPTYPE type, false).GetResultOrDefault()) { if (buffer != null) { ret.Type = type; ret.Data = buffer.ToArray(); } } return(ret); }
internal static DeviceProperty[] GetDeviceProperties(int dev_inst) { int count = 0; DeviceProperty[] props = new DeviceProperty[0]; DeviceNativeMethods.CM_Get_DevNode_Property_Keys(dev_inst, null, ref count, 0); if (count == 0) { return(new DeviceProperty[0]); } DEVPROPKEY[] keys = new DEVPROPKEY[count]; if (DeviceNativeMethods.CM_Get_DevNode_Property_Keys(dev_inst, keys, ref count, 0) != CrError.SUCCESS) { return(new DeviceProperty[0]); } return(keys.Take(count).Select(k => GetProperty(dev_inst, k)).ToArray()); }