发新话题
打印

求助:我认为一个很难的vb问题

求助:我认为一个很难的vb问题

我做了个打开关闭串口的程序,程序如下:Private Sub Command1_Click()
    Const GENERIC_READ = &H80000000
    Const GENERIC_WRITE = &H40000000
    Const OPEN_EXISTING = 3
    Const FILE_ATTRIBUTE_NORMAL = &H80
    Dim SecurityA As SECURITY_ATTRIBUTES
    hCom = CreateFile("COM1", GENERIC_READ Or GENERIC_WRITE, 0, SecurityA, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0)
    If hCom = -1 Then
        i = MsgBox("无法打开串口", vbOKOnly, "错误")
    End If
    End Sub

Private Sub Command2_Click()
CloseHandle (hCom)
End Sub
模块里声明如下:
Public Type SECURITY_ATTRIBUTES
        nLength As Long
        lpSecurityDescriptor As Long
        bInheritHandle As Long
End Type
Public Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As SECURITY_ATTRIBUTES, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Public hCom As Long '串口句柄
这个程序编好以后,编译成.exe文件后在win2000下能够成功打开和关闭串口,但我在win98下,点击打开串口框,却弹出"无法打开串口"对话框,这是为什么啊?据我了解Createfile这个API函数在win98里也可以用的啊!我百思不得其解,请求各位高人给我指点谢谢!联系:jiechen111@163.com

TOP

发新话题