vb6 用CreateFile打开串口出错!!!!!!!!!!!!
本帖最后由 a62520161 于 2012-08-30 17:35:59 编辑 声明
Private 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
使用
Dim sa As SECURITY_ATTRIBUTES
Dim hCF As Long
hCF = CreateFile("COM4", GENERIC_READ Or GENERIC_WRITE, 0, sa, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, 0)
怎么老是返回-1啊?????????
Dim errNum As Long
errNum = GetLastError()
errNum返回的是0
到底是什么原因啊!!!!!!!!!!!!!!!哪位大哥知道啊
Private Declare Function CreateFile Lib "kernel32 " Alias "CreateFileA " (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
ComNum = CreateFile( "COM1 ", &HC0000000, 0, 0&, &H3, 0, 0)
这个也不行
[解决办法]
C++这样写没有问题的,系统要有对应的com口。
HANDLE hComm = CreateFile("COM1",GENERIC_READ
[解决办法]
GENERIC_WRITE,
0, NULL, OPEN_EXISTING, 0, 0);
[解决办法]
http://download.csdn.net/detail/veron_04/1339593