comparison USBLib/Internal/Windows/SetupApi.cs @ 50:556b4fb511bd

Added HWLib and USBLib functions to support USB Driver Installer
author Ivo Smits <Ivo@UCIS.nl>
date Mon, 30 Sep 2013 19:23:09 +0200
parents 5b14fed54a89
children 309c705d7460
comparison
equal deleted inserted replaced
47:15ddb1e0e2a5 50:556b4fb511bd
39 39
40 [DllImport("setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)] 40 [DllImport("setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)]
41 public static extern bool SetupDiGetCustomDeviceProperty(SafeDeviceInfoSetHandle DeviceInfoSet, ref SP_DEVINFO_DATA DeviceInfoData, string CustomPropertyName, DICUSTOMDEVPROP Flags, out RegistryValueKind PropertyRegDataType, Byte[] PropertyBuffer, int PropertyBufferSize, out int RequiredSize); 41 public static extern bool SetupDiGetCustomDeviceProperty(SafeDeviceInfoSetHandle DeviceInfoSet, ref SP_DEVINFO_DATA DeviceInfoData, string CustomPropertyName, DICUSTOMDEVPROP Flags, out RegistryValueKind PropertyRegDataType, Byte[] PropertyBuffer, int PropertyBufferSize, out int RequiredSize);
42 [DllImport("setupapi.dll", SetLastError = true, CharSet = CharSet.Ansi)] 42 [DllImport("setupapi.dll", SetLastError = true, CharSet = CharSet.Ansi)]
43 public static extern bool SetupDiGetDeviceInstanceIdA(SafeDeviceInfoSetHandle DeviceInfoSet, ref SP_DEVINFO_DATA DeviceInfoData, StringBuilder DeviceInstanceId, int DeviceInstanceIdSize, out int RequiredSize); 43 public static extern bool SetupDiGetDeviceInstanceIdA(SafeDeviceInfoSetHandle DeviceInfoSet, ref SP_DEVINFO_DATA DeviceInfoData, StringBuilder DeviceInstanceId, int DeviceInstanceIdSize, out int RequiredSize);
44 [DllImport("setupapi.dll", CharSet = CharSet.Auto)] 44 [DllImport("setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)]
45 public static extern bool SetupDiGetDeviceRegistryProperty(SafeDeviceInfoSetHandle DeviceInfoSet, ref SP_DEVINFO_DATA DeviceInfoData, SPDRP Property, out RegistryValueKind PropertyRegDataType, byte[] PropertyBuffer, int PropertyBufferSize, out int RequiredSize);
46 [DllImport("setupapi.dll", SetLastError = true, CharSet = CharSet.Auto)]
47 public static extern bool SetupDiGetDeviceRegistryProperty(SafeDeviceInfoSetHandle DeviceInfoSet, ref SP_DEVINFO_DATA DeviceInfoData, SPDRP iProperty, out int PropertyRegDataType, IntPtr PropertyBuffer, int PropertyBufferSize, out int RequiredSize);
48 [DllImport("setupapi.dll", SetLastError = true, CharSet = CharSet.Auto)]
49 public static extern bool SetupDiGetDeviceRegistryProperty(SafeDeviceInfoSetHandle DeviceInfoSet, ref SP_DEVINFO_DATA DeviceInfoData, SPDRP iProperty, out int PropertyRegDataType, [MarshalAs(UnmanagedType.LPTStr)] StringBuilder PropertyBuffer, int PropertyBufferSize, out int RequiredSize);
50 [DllImport("setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)]
51 public static extern bool SetupDiSetDeviceRegistryProperty(SafeDeviceInfoSetHandle DeviceInfoSet, ref SP_DEVINFO_DATA DeviceInfoData, SPDRP Property, Byte[] PropertyBuffer, UInt32 PropertyBufferSize);
52
53 [DllImport("setupapi.dll", SetLastError = true, CharSet = CharSet.Auto)]
54 public static extern IntPtr SetupDiOpenDevRegKey(SafeDeviceInfoSetHandle DeviceInfoSet, ref SP_DEVINFO_DATA DeviceInfoData, UInt32 Scope, UInt32 HwProfile, UInt32 KeyType, UInt32 samDesired);
55 [DllImport("setupapi.dll", SetLastError = true, CharSet = CharSet.Auto)]
56 public static extern bool SetupDiGetDeviceProperty(SafeDeviceInfoSetHandle DeviceInfoSet, ref SP_DEVINFO_DATA DeviceInfoData, ref DEVPROPKEY PropertyKey, out UInt32 PropertyType, Byte[] PropertyBuffer, UInt32 PropertyBufferSize, out UInt32 RequiredSize, UInt32 Flags);
57 [DllImport("setupapi.dll", SetLastError = true, CharSet = CharSet.Auto)]
45 public static extern bool SetupDiGetDeviceInterfacePropertyKeys(SafeDeviceInfoSetHandle DeviceInfoSet, ref SP_DEVICE_INTERFACE_DATA DeviceInterfaceData, byte[] propKeyBuffer, int propKeyBufferElements, out int RequiredPropertyKeyCount, int Flags); 58 public static extern bool SetupDiGetDeviceInterfacePropertyKeys(SafeDeviceInfoSetHandle DeviceInfoSet, ref SP_DEVICE_INTERFACE_DATA DeviceInterfaceData, byte[] propKeyBuffer, int propKeyBufferElements, out int RequiredPropertyKeyCount, int Flags);
46 [DllImport("setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)]
47 public static extern bool SetupDiGetDeviceRegistryProperty(SafeDeviceInfoSetHandle DeviceInfoSet, ref SP_DEVINFO_DATA DeviceInfoData, SPDRP Property, out RegistryValueKind PropertyRegDataType, byte[] PropertyBuffer, int PropertyBufferSize, out int RequiredSize);
48 [DllImport("setupapi.dll", SetLastError = true, CharSet = CharSet.Auto)]
49 public static extern bool SetupDiGetDeviceRegistryProperty(SafeDeviceInfoSetHandle DeviceInfoSet, ref SP_DEVINFO_DATA DeviceInfoData, SPDRP iProperty, out int PropertyRegDataType, IntPtr PropertyBuffer, int PropertyBufferSize, out int RequiredSize);
50 [DllImport("setupapi.dll", SetLastError = true, CharSet = CharSet.Auto)]
51 public static extern bool SetupDiGetDeviceRegistryProperty(SafeDeviceInfoSetHandle DeviceInfoSet, ref SP_DEVINFO_DATA DeviceInfoData, SPDRP iProperty, out int PropertyRegDataType, [MarshalAs(UnmanagedType.LPTStr)] StringBuilder PropertyBuffer, int PropertyBufferSize, out int RequiredSize);
52 59
53 [DllImport("setupapi.dll", SetLastError = true, CharSet = CharSet.Auto)] 60 [DllImport("setupapi.dll", SetLastError = true, CharSet = CharSet.Auto)]
54 public static extern bool SetupDiGetDeviceInstanceId(SafeDeviceInfoSetHandle DeviceInfoSet, ref SP_DEVINFO_DATA DeviceInfoData, StringBuilder DeviceInstanceId, int DeviceInstanceIdSize, out int RequiredSize); 61 public static extern bool SetupDiGetDeviceInstanceId(SafeDeviceInfoSetHandle DeviceInfoSet, ref SP_DEVINFO_DATA DeviceInfoData, StringBuilder DeviceInstanceId, int DeviceInstanceIdSize, out int RequiredSize);
55 62
56 [DllImport("setupapi.dll")] 63 [DllImport("setupapi.dll")]
82 public static extern CR CM_Get_Device_Interface_List_Size(out UInt32 pulLen, [In] ref Guid InterfaceClassGuid, [MarshalAs(UnmanagedType.LPWStr)] String pDeviceID, UInt32 ulFlags); 89 public static extern CR CM_Get_Device_Interface_List_Size(out UInt32 pulLen, [In] ref Guid InterfaceClassGuid, [MarshalAs(UnmanagedType.LPWStr)] String pDeviceID, UInt32 ulFlags);
83 [DllImport("setupapi.dll", CharSet = CharSet.Auto)] 90 [DllImport("setupapi.dll", CharSet = CharSet.Auto)]
84 public static extern CR CM_Enumerate_Classes(UInt32 ulClassIndex, out Guid ClassGuid, UInt32 ulFlags); 91 public static extern CR CM_Enumerate_Classes(UInt32 ulClassIndex, out Guid ClassGuid, UInt32 ulFlags);
85 [DllImport("setupapi.dll", CharSet = CharSet.Auto)] 92 [DllImport("setupapi.dll", CharSet = CharSet.Auto)]
86 public static extern CR CM_Get_DevNode_Status(out UInt32 pulStatus, out UInt32 pulProblemNumber, UInt32 dnDevInst, UInt32 ulFlags); 93 public static extern CR CM_Get_DevNode_Status(out UInt32 pulStatus, out UInt32 pulProblemNumber, UInt32 dnDevInst, UInt32 ulFlags);
87 94 [DllImport("setupapi.dll", CharSet = CharSet.Auto)]
95 public static extern CR CM_Reenumerate_DevNode(UInt32 dnDevInst, UInt32 ulFlags);
88 96
89 //public const int DIGCF_DEFAULT = 0x00000001; // only valid with DIGCF_DEVICEINTERFACE 97 //public const int DIGCF_DEFAULT = 0x00000001; // only valid with DIGCF_DEVICEINTERFACE
90 public const int DIGCF_PRESENT = 0x00000002; 98 public const int DIGCF_PRESENT = 0x00000002;
91 public const int DIGCF_ALLCLASSES = 0x00000004; 99 public const int DIGCF_ALLCLASSES = 0x00000004;
92 public const int DIGCF_PROFILE = 0x00000008; 100 public const int DIGCF_PROFILE = 0x00000008;
192 //cbSize should be sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA) which is the same as the following 200 //cbSize should be sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA) which is the same as the following
193 //if DevicePath is a 1-byte array and the structure is properly padded... is it really? 201 //if DevicePath is a 1-byte array and the structure is properly padded... is it really?
194 if (IntPtr.Size == 8) cbSize = 8; //Workaround for x64 202 if (IntPtr.Size == 8) cbSize = 8; //Workaround for x64
195 else cbSize = 4 + (uint)Marshal.SystemDefaultCharSize; 203 else cbSize = 4 + (uint)Marshal.SystemDefaultCharSize;
196 } 204 }
205 }
206
207 [StructLayout(LayoutKind.Sequential)]
208 struct DEVPROPKEY {
209 public Guid fmtid;
210 public UInt32 pid;
197 } 211 }
198 212
199 enum CR { 213 enum CR {
200 SUCCESS = (0x00000000), 214 SUCCESS = (0x00000000),
201 DEFAULT = (0x00000001), 215 DEFAULT = (0x00000001),