BetterExplorer.UsbEject.Native.SetupDiGetDeviceRegistryProperty C# (CSharp) Method

SetupDiGetDeviceRegistryProperty() private method

private SetupDiGetDeviceRegistryProperty ( IntPtr deviceInfoSet, SP_DEVINFO_DATA deviceInfoData, int property, int &propertyRegDataType, IntPtr propertyBuffer, int propertyBufferSize, int &requiredSize ) : bool
deviceInfoSet System.IntPtr
deviceInfoData SP_DEVINFO_DATA
property int
propertyRegDataType int
propertyBuffer System.IntPtr
propertyBufferSize int
requiredSize int
return bool
        internal static extern bool SetupDiGetDeviceRegistryProperty(
            IntPtr deviceInfoSet,
            SP_DEVINFO_DATA deviceInfoData,
            int property,
            out int propertyRegDataType,
            IntPtr propertyBuffer,
            int propertyBufferSize,
            out int requiredSize
            );
        

Usage Example

Esempio n. 1
0
        internal Guid GetProperty(Native.SP_DEVINFO_DATA devData, int property, Guid defaultValue)
        {
            if (devData == null)
            {
                throw new ArgumentNullException("devData");
            }

            int propertyRegDataType = 0;
            int requiredSize;
            int propertyBufferSize = Marshal.SizeOf(typeof(Guid));

            IntPtr propertyBuffer = Marshal.AllocHGlobal(propertyBufferSize);

            if (!Native.SetupDiGetDeviceRegistryProperty(_deviceInfoSet,
                                                         devData,
                                                         property,
                                                         out propertyRegDataType,
                                                         propertyBuffer,
                                                         propertyBufferSize,
                                                         out requiredSize))
            {
                Marshal.FreeHGlobal(propertyBuffer);
                int error = Marshal.GetLastWin32Error();
                if (error != Native.ERROR_INVALID_DATA)
                {
                    throw new Win32Exception(error);
                }
                return(defaultValue);
            }

            Guid value = (Guid)Marshal.PtrToStructure(propertyBuffer, typeof(Guid));

            Marshal.FreeHGlobal(propertyBuffer);
            return(value);
        }