SetupDiGetDeviceProperty() private method

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
return bool
Esempio n. 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);
        }
Esempio n. 2
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);
        }