internal static extern bool GetDeviceProperty( IntPtr hInfoList, ref SP_DEVINFO_DATA deviceInfoData, ref DEVPROPKEY devicePropertyKey, [MarshalAs(UnmanagedType.U4)] out DevicePropertyType devicePropertyType, IntPtr propertyBuffer, int propertyBufferSize, out int requiredBufferSize, int flags);
/// <summary> /// Gets a property from the registry. See the <see cref="DevicePropertyType"/> enumeration for more information. /// </summary> /// <param name="devicePropertyType">The name of the property to retrieve.</param> /// <returns></returns> public object this[DevicePropertyType devicePropertyType] { get { object temp; mDeviceProperties.TryGetValue(devicePropertyType.ToString(), out temp); return(temp); } }
internal static string ToSerializedValue(this DevicePropertyType value) { switch (value) { case DevicePropertyType.String: return("string"); case DevicePropertyType.Number: return("number"); case DevicePropertyType.Boolean: return("boolean"); case DevicePropertyType.DateTime: return("date_time"); } return(null); }
/// <summary> /// /// </summary> /// <param name="device"></param> /// <param name="propertyKey"></param> /// <param name="propertyDataType"></param> /// <param name="requiredSize"></param> /// <returns></returns> public static bool GetDeviceProperty(DeviceInfo device, DevicePropertyKey propertyKey, out DevicePropertyType propertyDataType, out int requiredSize) { var deviceInfoList = device.InfoSet.InfoSet; var deviceInfoData = device.InfoData; var devicePropertyKey = propertyKey.PropertyKey; var success = GetDeviceProperty(deviceInfoList, ref deviceInfoData, ref devicePropertyKey, out propertyDataType, IntPtr.Zero, 0, out requiredSize, 0); if (!success) { var lastError = ErrorHelpers.GetLastError(); return(lastError == ErrorCode.InsufficientBuffer); } return(true); }
public static DevicePropertyValue Create(DevicePropertyType type, byte[] data) { switch (type) { case DevicePropertyType.UInt32: return(new DevicePropertyValueUInt32(type, data)); case DevicePropertyType.Guid: return(new DevicePropertyValueGuid(type, data)); case DevicePropertyType.String: return(new DevicePropertyValueString(type, data)); case DevicePropertyType.StringList: return(new DevicePropertyValueStringList(type, data)); } throw new NotImplementedException($"DevPropType {type} is not implemented"); }
/// <summary> /// /// </summary> /// <param name="device"></param> /// <param name="propertyKey"></param> /// <param name="propertyDataType"></param> /// <param name="propertyData"></param> /// <returns></returns> public static bool GetDeviceProperty(DeviceInfo device, DevicePropertyKey propertyKey, out DevicePropertyType propertyDataType, out Api.Buffer propertyData) { var deviceInfoList = device.InfoSet.InfoSet; var deviceInfoData = device.InfoData; var devicePropertyKey = propertyKey.PropertyKey; propertyData = new Api.Buffer(); int requiredSize; // Keep trying until we've got success or an unrecoverable error. while (true) { var success = GetDeviceProperty(deviceInfoList, ref deviceInfoData, ref devicePropertyKey, out propertyDataType, propertyData.Data, propertyData.Length, out requiredSize, 0); // If the data was read successfully, truncate the buffer to match the length read. if (success) { propertyData.Truncate(requiredSize); return(true); } // If the last error was for anything except the buffer being too small, cleanly get rid of the buffer // before returning failure. var lastError = ErrorHelpers.GetLastError(); if (lastError != ErrorCode.InsufficientBuffer) { propertyData.Dispose(); propertyData = null; return(false); } // Resize the buffer to the required length before trying again. propertyData.Resize(requiredSize); } }
/// <summary> /// Gets a property from the registry. See the <see cref="DevicePropertyType"/> enumeration for more information. /// </summary> /// <param name="devicePropertyType">The name of the property to retrieve.</param> /// <returns></returns> public object this[DevicePropertyType devicePropertyType] { get { object temp; mDeviceProperties.TryGetValue(devicePropertyType.ToString(), out temp); return temp; } }
public DevicePropertyValueStringList(DevicePropertyType type, byte[] data) : base(type) { Value = data.SeparateRegMultiSz(); }
public DevicePropertyValueString(DevicePropertyType type, byte[] data) : base(type) { Value = Encoding.Unicode.GetString(data); }
public DevicePropertyValueGuid(DevicePropertyType type, byte[] data) : base(type) { Value = new Guid(data); }
public DevicePropertyValueUInt32(DevicePropertyType type, byte[] data) : base(type) { Value = BitConverter.ToUInt32(data, 0); }
protected DevicePropertyValue(DevicePropertyType type) { Type = type; }