标题:请高手帮忙解答一下,调用SetupDiGetDeviceInterfaceDetail出现错误,USB通 ...
只看楼主
Chingle
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2017-3-29
 问题点数:0 回复次数:0 
请高手帮忙解答一下,调用SetupDiGetDeviceInterfaceDetail出现错误,USB通信时出现的问题
HidD_GetHidGuid(guidHID)
hDevInfo = SetupDiGetClassDevs(guidHID, 0, 0, DIGCF.DIGCF_PRESENT Or DIGCF.DIGCF_DEVICEINTERFACE)

DeviceInterfaceData.cbSize = Marshal.SizeOf(GetType(SP_DEVICE_INTERFACE_DATA))
DetailData.cbSize = Marshal.SizeOf(GetType(SP_DEVICE_INTERFACE_DETAIL_DATA))
strtInterfaceData.cbSize = Marshal.SizeOf(GetType(SP_DEVINFO_DATA))

result = SetupDiEnumDeviceInterfaces(hDevInfo, 0, guidHID, MemberIndex, DeviceInterfaceData)

--这之前的运行都是没有问题的

result = SetupDiGetDeviceInterfaceDetail(hDevInfo, DeviceInterfaceData, DetailData, 0, bufferSize, strtInterfaceData)
--第一遍调用说成功
result = SetupDiGetDeviceInterfaceDetail(hDevInfo, DeviceInterfaceData, DetailData, bufferSize, bufferSize, strtInterfaceData)
--第二遍调用说提供给请求操作的用户缓冲区无效

下面是其中结构体的定义以及函数的调用
    <StructLayout(LayoutKind.Sequential)>
    Public Structure SP_DEVICE_INTERFACE_DATA
        Public cbSize As UInteger
        Public interfaceClassGuid As Guid
        Public flags As UInteger
        Public reserved As IntPtr
    End Structure

    <StructLayout(LayoutKind.Sequential)>
    Public Structure SP_DEVINFO_DATA
        Public cbSize As Integer
        Public classGuid As Guid
        Public propertyId As Integer
        Public reserved As IntPtr
    End Structure

    <StructLayout(LayoutKind.Sequential)>
    Public Structure SP_DEVICE_INTERFACE_DETAIL_DATA
        Public cbSize As UInt32
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=256)> Public DevicePath As String
    End Structure

--函数
<DllImport("setupapi.dll", EntryPoint:="SetupDiGetClassDevsW", SetLastError:=True, CharSet:=CharSet.Unicode, ExactSpelling:=True, PreserveSig:=True, CallingConvention:=CallingConvention.Winapi)>
    Private Shared Function SetupDiGetClassDevs(
        ByRef ClassGuid As Guid,
        ByVal Enumerator As Integer,
        ByVal hwndParent As Integer,
        ByVal Flags As Integer) As IntPtr
    End Function

    <DllImport("setupapi.dll", CharSet:=CharSet.Auto, SetLastError:=True)>
    Public Shared Function SetupDiEnumDeviceInterfaces(
                                                      ByVal hDevInfo As IntPtr,
                                                      ByVal devInfo As Integer,
                                                      ByRef interfaceClassGuid As Guid,
                                                      ByVal memberIndex As UInt32,
                                                      ByRef deviceInterfaceData As SP_DEVICE_INTERFACE_DATA) As Boolean
    End Function

    Public Declare Auto Function SetupDiGetDeviceInterfaceDetail Lib "setupapi.dll" Alias "SetupDiGetDeviceInterfaceDetailW" _
        (ByVal hDevInfo As IntPtr,
         ByRef deviceInterfaceData As SP_DEVICE_INTERFACE_DATA,
         ByRef deviceInterfaceDetailData As SP_DEVICE_INTERFACE_DETAIL_DATA,
         ByVal deviceInterfaceDetailDataSize As Int32,
         ByRef requiredSize As Int32,
         ByRef deviceInfoData As SP_DEVINFO_DATA) As Boolean

[此贴子已经被作者于2017-3-29 11:48编辑过]

搜索更多相关主题的帖子: result 通信 
2017-03-29 11:44



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-475617-1-1.html




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

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