| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 945 人关注过本帖
标题:为什么不能获得USB设备句柄
取消只看楼主 加入收藏
kk205
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2005-5-4
收藏
 问题点数:0 回复次数:0 
为什么不能获得USB设备句柄
我用VB写的应用程序,用的是68013芯片,驱动程序也已经安装好,并且操作系统已经能识别设备,可是应用程序用creatfile就是打不开设备,得不到设备句柄。代码如下:
Private Sub Form_Load()
'Handle HidDevice
Dim HidDevice As Long

DevicePathName = "\\.\ezusb-0"

HidDevice = CreateFile _
          (DevicePathName, _
          GENERIC_WRITE, _
          FILE_SHARE_WRITE, _
          0, _
          OPEN_EXISTING, _
          0, _
          0)
         
    'INVALID_HANDLE_VALUE = -1
    If (HidDevice = INVALID_HANDLE_VALUE) Then
      'OpenDevice = False
     
     
      'Form1.Shape6.Height = (MaxTemper - 0) * TemperScale
    
      MsgBox " 未发现与之通信的USB设备!" + _
       Chr(13) & Chr(10) + _
       Chr(13) & Chr(10) + _
       " 请确定其硬件设备是否已连接," + _
       Chr(13) & Chr(10) + _
       "并确定其驱动程序是否已加载。", _
       17, "可恶"
     
    
    Else
    MsgBox " 发现与之通信的USB设备!" + _
       Chr(13) & Chr(10) + _
       Chr(13) & Chr(10) + _
       " 请确定," + _
       Chr(13) & Chr(10) + _
       "!", _
       1, "成功打开设备"
     
      'OpenDevice = True
    End If
End Sub


Public Declare Function CreateFile _
   Lib "kernel32" _
   Alias "CreateFileA" _
    (ByVal lpFileName As String, _
    ByVal dwDesiredAccess As Long, _
    ByVal dwShareMode As Long, _
    ByRef lpSecurityAttributes As Long, _
    ByVal dwCreationDisposition As Long, _
    ByVal dwFlagsAndAttributes As Long, _
    ByVal hTemplateFile As Long) _
As Long


'*****************************************************************
'API constants.
'*****************************************************************
'IOCTL Code
'Public Const FILE_DEVICE_UNKNOWN = &H22
Public Const Cyusb_IOCTL_INDEX = &H800
Public Const METHOD_BUFFERED = &H0
Public Const FILE_ANY_ACCESS = &H0
'CreateFile
Public Const GENERIC_READ = &H80000000
Public Const GENERIC_WRITE = &H40000000
Public Const FILE_SHARE_READ = &H1
Public Const FILE_SHARE_WRITE = &H2
Public Const OPEN_EXISTING = 3
'Public Const INVALID_HANDLE_VALUE = -1
Public Const INVALID_HANDLE_VALUE = -1
搜索更多相关主题的帖子: 句柄 USB 设备 
2005-05-04 21:24
快速回复:为什么不能获得USB设备句柄
数据加载中...
 
   



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

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