SetupDiGetDeviceInterfaceDetail这个函数调用不成功,网上各种方法各种试还是不行,求高手解答?

袁梦 2017-07-02 03:14:28

'驱动器API
Private Declare Function SetupDiGetClassDevs Lib "SetupAPI" Alias "SetupDiGetClassDevsA" (ClassGuid As Any, ByVal Enumerator As String, ByVal hParentWnd As Long, ByVal Flags As Long) As Long
Private Declare Function SetupDiGetClassDevsEx Lib "SetupAPI" Alias "SetupDiGetClassDevsExA" (ClassGuid As Any, ByVal Enumerator As String, ByVal hParentWnd As Long, ByVal Flags As Long, DeviceInfoSet As Any, ByVal MachineName As String, ByVal Reserved As Long) As Long
Private Declare Function SetupDiEnumDeviceInfo Lib "SetupAPI" (ByVal DeviceInfoSet As Long, ByVal MemberIndex As Long, DeviceInfoData As Any) As Long
Private Declare Function SetupDiEnumDeviceInterfaces Lib "SetupAPI" (ByVal DeviceInfoSet As Long, DeviceInfoData As Any, InterfaceClassGuid As Any, ByVal MemberIndex As Long, DeviceInterfaceData As Any) As Long
Private Declare Function SetupDiEnumDriverInfo Lib "SetupAPI" (ByVal DeviceInfoSet As Long, DeviceInfoData As Any, ByVal DriverType As Long, ByVal MemberIndex As Long, DeviceInterfaceData As Any) As Long
Private Declare Function SetupDiGetDeviceInterfaceDetail Lib "SetupAPI" Alias "SetupDiGetDeviceInterfaceDetailA" (ByVal DeviceInfoSet As Long, DeviceInterfaceData As Any, DeviceInterfaceDetailData As Any, ByVal DeviceInterfaceDetailDataSize As Long, RequiredSize As Long, DeviceInfoData As Any) As Long
Private Declare Function SetupDiInstallDeviceInterfaces Lib "SetupAPI" (ByVal DeviceInfoSet As Long, DeviceInfoData As Any) As Long
Private Declare Function SetupDiRemoveDeviceInterface Lib "SetupAPI" (ByVal DeviceInfoSet As Long, DeviceInfoData As Any) As Long
Private Declare Function SetupDiDestroyDriverInfoList Lib "SetupAPI" (ByVal DeviceInfoSet As Long, DeviceInfoData As Any, ByVal DriverType As Long) As Long
Private Declare Function SetupDiDestroyDeviceInfoList Lib "SetupAPI" (ByVal DeviceInfoSet As Long) As Long
Private Const DIGCF_DEFAULT = &H1 '// only valid with DIGCF_DEVICEINTERFACE
Private Const DIGCF_PRESENT = &H2
Private Const DIGCF_ALLCLASSES = &H4
Private Const DIGCF_PROFILE = &H8
Private Const DIGCF_DEVICEINTERFACE = &H10
Private Const ERROR_NO_MORE_ITEMS = 259&
Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(7) As Byte
End Type
Private Type SP_DEVINFO_DATA
cbSize As Long
ClassGuid As GUID
DevInst As Long
Reserved As Long
End Type
Private Type SP_DEVICE_INTERFACE_DATA
cbSize As Long
InterfaceClassGuid As GUID
Flags As Long
Reserved As Long
End Type
Private Type SP_DEVICE_INTERFACE_DETAIL_DATA
cbSize As Long
DevicePath As Long
End Type

'获取磁盘信息
Private Function EnumDiskVolumeInfo() As Long
Dim DeviceInfoSet As Long, MemberIndex As Long, ReturnSize As Long, DeviceDataPoint As Long, ErrCode As Long, VolumePath As String, DevicePath() As Byte, ClassGuid As GUID, DeviceInfo As SP_DEVINFO_DATA, DeviceInterFace As SP_DEVICE_INTERFACE_DATA, DeviceInterFaceDetail As SP_DEVICE_INTERFACE_DETAIL_DATA
DeviceInfoSet = SetupDiGetClassDevs(ByVal 0, vbNullString, 0, DIGCF_ALLCLASSES Or DIGCF_DEVICEINTERFACE Or DIGCF_PROFILE)
If DeviceInfoSet <> -1 Then
MemberIndex = 0
ClassGuid.Data1 = &H53F56307
ClassGuid.Data2 = &HB6BF
ClassGuid.Data3 = &H11D0
ClassGuid.Data4(0) = &H94
ClassGuid.Data4(1) = &HF2
ClassGuid.Data4(2) = 0
ClassGuid.Data4(3) = &HA0
ClassGuid.Data4(4) = &HC9
ClassGuid.Data4(5) = &H1E
ClassGuid.Data4(6) = &HFB
ClassGuid.Data4(7) = &H8B
DeviceInterFace.cbSize = Len(DeviceInterFace)
Do While SetupDiEnumDeviceInterfaces(DeviceInfoSet, ByVal 0, ClassGuid, MemberIndex, DeviceInterFace)
SetupDiGetDeviceInterfaceDetail DeviceInfoSet, DeviceInterFace, ByVal 0, 0, ReturnSize, ByVal 0
If ReturnSize > 0 Then
'DeviceInfo.cbSize = 28
'VolumePath = ChrW(ReturnSize) & String(ReturnSize, vbNullChar)
'ReDim DevicePath(7)
'CopyMemory DevicePath(0), 8&, 4
'CopyMemory DevicePath(4), StrPtr(VolumePath), 4
ReturnSize = ReturnSize * 2
DeviceInterFaceDetail.cbSize = 8
DeviceInterFaceDetail.DevicePath = LocalAlloc(&H40, ReturnSize)
LocalLock DeviceInterFaceDetail.DevicePath
CopyMemory ByVal DeviceInterFaceDetail.DevicePath, ReturnSize, 4
SetupDiGetDeviceInterfaceDetail DeviceInfoSet, DeviceInterFace, DeviceInterFaceDetail, ReturnSize, ReturnSize, ByVal 0
ErrCode = GetLastError
Debug.Print ErrCode ', DeviceInterFaceDetail.DevicePath
LocalUnlock DeviceInterFaceDetail.DevicePath
LocalFree DeviceInterFaceDetail.DevicePath
ZeroMemory DeviceInterFaceDetail, 8
'ZeroMemory DeviceInfo, 28
End If
MemberIndex = MemberIndex + 1
Loop
SetupDiDestroyDeviceInfoList DeviceInfoSet
End If
EnumDiskVolumeInfo = MemberIndex
End Function

...全文
1101 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复

1,486

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧