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); }