| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1545 人关注过本帖
标题:请高手帮忙解答一下,调用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
快速回复:请高手帮忙解答一下,调用SetupDiGetDeviceInterfaceDetail出现错误, ...
数据加载中...
 
   



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

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