帮忙看一个VB程序

来源:百度知道 编辑:UC知道 时间:2024/05/31 06:34:37
Private Declare Function CreateFile Lib "kerne132" Alias "CreateFileA" (ByVal IpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, IpSecurityAttributes As SECURITY_ATTRIBUTES, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function CloseHandle Lib "kerne132" (ByVal hObject As Long) As Long
Private Declare Function GetCommState Lib "kerne132" (ByVal nCid As Long, lpDCB As DCB) As Long
Private Declare Function SetCommState Lib "kerne132" (ByVal hCommDev As Long, lpDCB As DCB) As Long
Private Declare Function WriteFile Lib "kerne132" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, lpOverlapped As OVERLAPPED) As Long
Private Declare Function ReadFile Lib "kerne132" (ByVal hFile As Long, lpBuffer As Any, ByVal nNum

Private Type SECURITY_ATTRIBUTES
nLengh As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type
少了一个Private

加一个private
Private Type SECURITY_ATTRIBUTES
nLengh As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type
Form_Load事件如下:
Private Sub Form_Load()
Dim dcb0 As DCB
Dim typeSA As SECURITY_ATTRIBUTES//我加的
typeSA.bInheritHandle = 0//设置你的具体值
typeSA.lpSecurityDescriptor = 0//设置你的具体值
typeSA.nLengh = 0//设置你的具体值
com1_h = CreateFile("com1", (GENERIC_READ Or GENERIC_WRITE), 0, typeSA, OPEN_EXISTING, O, 0)//原来的0改成了变量
GetCommState com1_h, dcb0
dcb0.BaudRate = 4800
dcb0.ByteSize = 8
dcb0.Parity = 1
SetCommState com1_h, dcb0//原来的这句写错了,少了一个t
End Sub
好了

学学

呵呵,楼主在哪里复制的代码啊?
还没搞懂就粘贴

必须将Type 语句放在模块级中使用,
你可以新增一个Module由於需要在后面的窗体中使用,所以你应该将Private去除。

学学~