您的位置:程序门 -> vb ->



vb 应用于usb设计的 问题(2)


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


vb 应用于usb设计的 问题(2)
发表于:2007-04-15 21:26:49 楼主
接着上一个帖子的问题:
private   sub   form_load()


dim   result   as   long
dim   memberindex   as   long
dim   deviceinfoset   as   long
dim   mydeviceinterfacedata   as   sp_device_interface_data
dim   detaildata   as   long
dim   mydeviceinterfacedetaildata   as   sp_device_interface_detail_data
dim   needed   as   long
dim   devicepathname   as   string
dim   hiddevice   as   long
dim   capabilities   as   hidp_caps
dim   nummax   as   integer
dim   hidguid   as   guid
dim   adevice   as   adevice
dim   preparseddata   as   long
dim   szstore(63)   as   byte     '调用readfile()用
dim   dwcount   as   long


'/*   get   guid   for   all   system   hids   */
        result   =   hidd_gethidguid(hidguid)

'/*   get   device   information   for   all   present   devices   */
        deviceinfoset   =   setupdigetclassdevs(   _
                                                                        hidguid,   _
                                                                        vbnullstring,   _
                                                                        0,   _
                                                                        (digcf_present   or   digcf_deviceinterface))
       
'/*   scan   all   devices   */           查找设备
        memberindex   =   0
        adevice.total   =   0
        do
       
                mydeviceinterfacedata.cbsize   =   lenb(mydeviceinterfacedata)
'/*   device   interface   element   of   a   device   information   set   */
                result   =   setupdienumdeviceinterfaces(   _
                                                                                                deviceinfoset,   _
                                                                                                0,   _
                                                                                                hidguid,   _
                                                                                                memberindex,   _
                                                                                                mydeviceinterfacedata)
                memberindex   =   memberindex   +   1
                if   result   =   0   then   exit   do

'/*   get   device   interface   details   -   get   length   */
'第一次调用函数deviceinfoset,mydeviceinterfacedata是传回结构
'needed包含要传给下一个调用的缓冲区大小
                result   =   setupdigetdeviceinterfacedetail(   _
                                                                                                deviceinfoset,   _
                                                                                                mydeviceinterfacedata,   _
                                                                                                0,   _
                                                                                                0,   _
                                                                                                needed,   _
                                                                                                0)
                                                                                       
'要传给下一个调用的   detaildata=needed
                detaildata   =   needed
                mydeviceinterfacedetaildata.cbsize   =   len(mydeviceinterfacedetaildata)
'use   a   byte   array   to   allocate   memory   for
'the   mydeviceinterfacedetaildata   structure
                redim   detaildatabuffer(needed)
'字节数组的前4个字节是数组的大小
                call   rtlmovememory(detaildatabuffer(0),   mydeviceinterfacedetaildata,   4)
'varptr(detaildatabuffer(0))是包含mydeviceinterfacedetaildata的字节数组的开始地址
'detaildata储存上一个调用所传回的大小
                result   =   setupdigetdeviceinterfacedetail(   _
                                                                                                deviceinfoset,   _
                                                                                                mydeviceinterfacedata,   _
                                                                                                varptr(detaildatabuffer(0)),   _
                                                                                                detaildata,   _
                                                                                                needed,   _
                                                                                                0)

                                                                                               
                if   result   =   0   then   goto   do_next
               
               
                devicepathname   =   cstr(detaildatabuffer(0))
                'convert   to   unicode.
                devicepathname   =   strconv(devicepathname,   vbunicode)
                'strip   cbsize   (4   bytes)   from   the   beginning.
                devicepathname   =   right$(devicepathname,   len(devicepathname)   -   4)
               
               
                hiddevice   =   createfile(   _
                                                                        devicepathname,   _
                                                                        generic_read   or   generic_write,   _
                                                                        (file_share_read   or   file_share_write),   _
                                                                        0,   _
                                                                        open_existing,   _
                                                                        0,   _
                                                                        0)

                if   hiddevice   =   invalid_handle_value   then   goto   do_next
               
                result   =   hidd_getpreparseddata(   _
                                                                                        hiddevice,   _
                                                                                        preparseddata)
                if   result   =   0   then   goto   do_next
                result   =   hidp_getcaps(   _
                                                                preparseddata,   _
                                                                capabilities)
                if   (capabilities.usagepage   =   &hff00)   and   (capabilities.usage   =   &h1)   then
                        adevice.devicepath(adevice.total)   =   devicepathname
                        adevice.total   =   adevice.total   +   1
                end   if
do_next:
               
        loop   until   nummax   <   adevice.total

        call   readfile(hiddevice,   szstore(0),   4,   dwcount,   0)

dim   adr_l   as   integer
dim   adr_h   as   integer
dim   length   as   integer
dim   str   as   string
str   =   readusb(adr_l,   adr_h,   length)

text1   =   str

end   sub


快速检索

最新资讯
热门点击