コード例 #1
0
 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);
コード例 #2
0
ファイル: UsbRegistry.cs プロジェクト: youyong/LibUsbDotNet
 /// <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);
     }
 }
コード例 #3
0
        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);
        }
コード例 #4
0
        /// <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);
        }
コード例 #5
0
        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");
        }
コード例 #6
0
        /// <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);
            }
        }
コード例 #7
0
 /// <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;
     }
 }
コード例 #8
0
 public DevicePropertyValueStringList(DevicePropertyType type, byte[] data) : base(type)
 {
     Value = data.SeparateRegMultiSz();
 }
コード例 #9
0
 public DevicePropertyValueString(DevicePropertyType type, byte[] data) : base(type)
 {
     Value = Encoding.Unicode.GetString(data);
 }
コード例 #10
0
 public DevicePropertyValueGuid(DevicePropertyType type, byte[] data) : base(type)
 {
     Value = new Guid(data);
 }
コード例 #11
0
 public DevicePropertyValueUInt32(DevicePropertyType type, byte[] data) : base(type)
 {
     Value = BitConverter.ToUInt32(data, 0);
 }
コード例 #12
0
 protected DevicePropertyValue(DevicePropertyType type)
 {
     Type = type;
 }