| 网站首页 | 业界新闻 | 小组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
共有 683 人关注过本帖
标题:SetupDiGetDeviceInterfaceDetail无法获取磁盘路径信息,求高手解答!
只看楼主 加入收藏
qw1070537606
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2017-7-14
  问题点数:0  回复次数:1   
SetupDiGetDeviceInterfaceDetail无法获取磁盘路径信息,求高手解答!
程序代码:

'驱动器API(https://msdn.(v=vs.85).aspx)
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(519) As Byte
End Type
Private Const SPINT_ACTIVE = &H1
Private Const SPINT_DEFAULT = &H2
Private Const SPINT_REMOVED = &H4

'获取磁盘信息
Private Function EnumDiskVolumeInfo() As Long
Dim DeviceInfoSet As Long, MemberIndex As Long, ReturnSize As Long, OldIrql 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
         VolumePath = String(ReturnSize, vbNullChar)
         'RtlInitUnicodeString DeviceDataPoint, VolumePath
         DeviceInterFaceDetail.cbSize = 8
         'DeviceInterFaceDetail.DevicePath = VolumePath ' LocalAlloc(&H40, ReturnSize)
         'LocalLock DeviceInterFaceDetail.DevicePath
         'CopyMemory ByVal DeviceInterFaceDetail.DevicePath, ReturnSize, 4
         SetupDiGetDeviceInterfaceDetail DeviceInfoSet, DeviceInterFace, DeviceInterFaceDetail, ReturnSize, ReturnSize, ByVal 0
         Debug.Print GetLastError
         'LocalUnlock DeviceInterFaceDetail.DevicePath
         'LocalFree DeviceInterFaceDetail.DevicePath
         ZeroMemory DeviceInterFaceDetail, 8
      End If
      MemberIndex = MemberIndex + 1
   Loop
   SetupDiDestroyDeviceInfoList DeviceInfoSet
End If
EnumDiskVolumeInfo = MemberIndex
End Function
搜索更多相关主题的帖子: Lib Private Function ByVal Long 
2017-07-14 10:56
qw1070537606
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2017-7-14
  得分:0 
typedef struct _SP_DEVICE_INTERFACE_DETAIL_DATA { DWORD cbSize; TCHAR DevicePath[ANYSIZE_ARRAY]; } SP_DEVICE_INTERFACE_DETAIL_DATA, *PSP_DEVICE_INTERFACE_DETAIL_DATA; 这个我理解错了,DevicePath我理解为字符串指针,其实它表示第一个字节 ,所以DeviceInterFaceDetail.cbSize = 5
2017-07-15 01:51
快速回复:SetupDiGetDeviceInterfaceDetail无法获取磁盘路径信息,求高手解答!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.057550 second(s), 9 queries.
Copyright©2004-2019, BCCN.NET, All Rights Reserved