forked from SigmaDolphin/SkylanderEditor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeviceManagementDeclarations.vb
129 lines (107 loc) · 4.2 KB
/
DeviceManagementDeclarations.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
Option Strict On
Option Explicit On
Imports System.Runtime.InteropServices
Partial Friend NotInheritable Class DeviceManagement
'''<remarks>
''' API declarations relating to device management (SetupDixxx and
''' RegisterDeviceNotification functions).
''' Constants are from dbt.h and setupapi.h.
'''</remarks>
Friend Const DBT_DEVICEARRIVAL As Int32 = &H8000
Friend Const DBT_DEVICEREMOVECOMPLETE As Int32 = &H8004
Friend Const DBT_DEVTYP_DEVICEINTERFACE As Int32 = 5
Friend Const DBT_DEVTYP_HANDLE As Int32 = 6
Friend Const DEVICE_NOTIFY_ALL_INTERFACE_CLASSES As Int32 = 4
Friend Const DEVICE_NOTIFY_SERVICE_HANDLE As Int32 = 1
Friend Const DEVICE_NOTIFY_WINDOW_HANDLE As Int32 = 0
Friend Const WM_DEVICECHANGE As Int32 = &H219
Friend Const DIGCF_PRESENT As Int32 = 2
Friend Const DIGCF_DEVICEINTERFACE As Int32 = &H10
'Two declarations for the DEV_BROADCAST_DEVICEINTERFACE structure.
'Use this one in the call to RegisterDeviceNotification() and
'in checking dbch_devicetype in a DEV_BROADCAST_HDR structure:
<StructLayout(LayoutKind.Sequential)> _
Friend Class DEV_BROADCAST_DEVICEINTERFACE
Friend dbcc_size As Int32
Friend dbcc_devicetype As Int32
Friend dbcc_reserved As Int32
Friend dbcc_classguid As Guid
Friend dbcc_name As Int16
End Class
'Use this to read the dbcc_name string and classguid:
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
Friend Class DEV_BROADCAST_DEVICEINTERFACE_1
Friend dbcc_size As Int32
Friend dbcc_devicetype As Int32
Friend dbcc_reserved As Int32
<MarshalAs(UnmanagedType.ByValArray, ArraySubType:=UnmanagedType.U1, SizeConst:=16)> _
Friend dbcc_classguid() As Byte
<MarshalAs(UnmanagedType.ByValArray, sizeconst:=255)> _
Friend dbcc_name() As Char
End Class
<StructLayout(LayoutKind.Sequential)> _
Friend Class DEV_BROADCAST_HDR
Friend dbch_size As Int32
Friend dbch_devicetype As Int32
Friend dbch_reserved As Int32
End Class
Friend Structure SP_DEVICE_INTERFACE_DATA
Friend cbSize As Int32
Friend InterfaceClassGuid As System.Guid
Friend Flags As Int32
Friend Reserved As IntPtr
End Structure
Friend Structure SP_DEVICE_INTERFACE_DETAIL_DATA
Friend cbSize As Int32
Friend DevicePath As String
End Structure
Friend Structure SP_DEVINFO_DATA
Friend cbSize As Int32
Friend ClassGuid As System.Guid
Friend DevInst As Int32
Friend Reserved As Int32
End Structure
<DllImport("user32.dll", CharSet:=CharSet.Auto, SetLastError:=True)> Shared Function RegisterDeviceNotification _
(ByVal hRecipient As IntPtr, _
ByVal NotificationFilter As IntPtr, _
ByVal Flags As Int32) _
As IntPtr
End Function
<DllImport("setupapi.dll", SetLastError:=True)> Shared Function SetupDiCreateDeviceInfoList _
(ByRef ClassGuid As System.Guid, _
ByVal hwndParent As Int32) _
As Int32
End Function
<DllImport("setupapi.dll", SetLastError:=True)> Shared Function SetupDiDestroyDeviceInfoList _
(ByVal DeviceInfoSet As IntPtr) _
As Int32
End Function
<DllImport("setupapi.dll", SetLastError:=True)> Shared Function SetupDiEnumDeviceInterfaces _
(ByVal DeviceInfoSet As IntPtr, _
ByVal DeviceInfoData As IntPtr, _
ByRef InterfaceClassGuid As System.Guid, _
ByVal MemberIndex As Int32, _
ByRef DeviceInterfaceData As SP_DEVICE_INTERFACE_DATA) _
As Boolean
End Function
<DllImport("setupapi.dll", CharSet:=CharSet.Auto, SetLastError:=True)> Shared Function SetupDiGetClassDevs _
(ByRef ClassGuid As System.Guid, _
ByVal Enumerator As IntPtr, _
ByVal hwndParent As IntPtr, _
ByVal Flags As Int32) _
As IntPtr
End Function
<DllImport("setupapi.dll", CharSet:=CharSet.Auto, SetLastError:=True)> Shared Function SetupDiGetDeviceInterfaceDetail _
(ByVal DeviceInfoSet As IntPtr, _
ByRef DeviceInterfaceData As SP_DEVICE_INTERFACE_DATA, _
ByVal DeviceInterfaceDetailData As IntPtr, _
ByVal DeviceInterfaceDetailDataSize As Int32, _
ByRef RequiredSize As Int32, _
ByVal DeviceInfoData As IntPtr) _
As Boolean
End Function
<DllImport("user32.dll", SetLastError:=True)> Shared Function UnregisterDeviceNotification _
(ByVal Handle As IntPtr) _
As Boolean
End Function
End Class