SetupDiGetDeviceProperty() приватный Метод

private SetupDiGetDeviceProperty ( IntPtr deviceInfo, SP_DEVINFO_DATA &deviceInfoData, DEVPROPKEY &propkey, ulong &propertyDataType, byte propertyBuffer, int propertyBufferSize, int &requiredSize, uint flags ) : bool
deviceInfo System.IntPtr
deviceInfoData SP_DEVINFO_DATA
propkey DEVPROPKEY
propertyDataType ulong
propertyBuffer byte
propertyBufferSize int
requiredSize int
flags uint
Результат bool
Пример #1
0
        private static string GetBusReportedDeviceDescription(IntPtr deviceInfoSet, ref NativeMethods.SP_DEVINFO_DATA devinfoData)
        {
            var descriptionBuffer = new byte[1024];

            if (Environment.OSVersion.Version.Major > 5)
            {
                ulong propertyType = 0;
                var   requiredSize = 0;

                var _continue = NativeMethods.SetupDiGetDeviceProperty(deviceInfoSet,
                                                                       ref devinfoData,
                                                                       ref NativeMethods.DEVPKEY_Device_BusReportedDeviceDesc,
                                                                       ref propertyType,
                                                                       descriptionBuffer,
                                                                       descriptionBuffer.Length,
                                                                       ref requiredSize,
                                                                       0);

                if (_continue)
                {
                    return(descriptionBuffer.ToUTF16String());
                }
            }
            return(null);
        }
Пример #2
0
        private static string GetBusReportedDeviceDescription(IntPtr deviceInfoSet, ref NativeMethods.SP_DEVINFO_DATA devinfoData)
        {
            unsafe
            {
                const int charCount         = 1024;
                var       descriptionBuffer = stackalloc char[charCount];

                if (Environment.OSVersion.Version.Major > 5)
                {
                    uint propertyType = 0;
                    var  requiredSize = 0;

                    if (NativeMethods.SetupDiGetDeviceProperty(deviceInfoSet,
                                                               ref devinfoData,
                                                               ref NativeMethods.DEVPKEY_Device_BusReportedDeviceDesc,
                                                               ref propertyType,
                                                               descriptionBuffer,
                                                               propertyBufferSize: charCount *sizeof(char),
                                                               ref requiredSize,
                                                               0))
                    {
                        return(new string(descriptionBuffer));
                    }
                }

                return(null);
            }
        }
Пример #3
0
        private static string GetDeviceParent(IntPtr deviceInfoSet, ref NativeMethods.SP_DEVINFO_DATA devinfoData)
        {
            string result = string.Empty;

            var   requiredSize = 0;
            ulong propertyType = 0;

            NativeMethods.SetupDiGetDeviceProperty(deviceInfoSet, ref devinfoData,
                                                   ref NativeMethods.DEVPKEY_Device_Parent, ref propertyType,
                                                   null, 0,
                                                   ref requiredSize, 0);

            if (requiredSize > 0)
            {
                var descriptionBuffer = new byte[requiredSize];
                NativeMethods.SetupDiGetDeviceProperty(deviceInfoSet, ref devinfoData,
                                                       ref NativeMethods.DEVPKEY_Device_Parent, ref propertyType,
                                                       descriptionBuffer, descriptionBuffer.Length,
                                                       ref requiredSize, 0);

                string tmp = System.Text.Encoding.Unicode.GetString(descriptionBuffer);
                if (tmp.EndsWith("\0"))
                {
                    tmp = tmp.Remove(tmp.Length - 1);
                }
                result = tmp;
            }

            return(result);
        }
Пример #4
0
 private static string GetBusReportedDeviceDescription(IntPtr deviceInfoSet, ref NativeMethods.SP_DEVINFO_DATA devinfoData)
 {
     byte[] array = new byte[1024];
     if (Environment.OSVersion.Version.Major > 5)
     {
         ulong propertyDataType = 0uL;
         int   requiredSize     = 0;
         if (NativeMethods.SetupDiGetDeviceProperty(deviceInfoSet, ref devinfoData, ref NativeMethods.DEVPKEY_Device_BusReportedDeviceDesc, ref propertyDataType, array, array.Length, ref requiredSize, 0u))
         {
             return(array.ToUTF16String());
         }
     }
     return(null);
 }