本人想用API函数实现串口操作,其中使用到createfile函数,编译时提示ByRef参数类型不符,声明createfile函数如下,是从API浏览器里复制过来的,
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
使用时如下:
Com1_h = CreateFile("com1", (GENERIC_READ Or GENERIC_WRITE), 0, 0, OPEN_EXISTING, O, 0)
总是提示第四个参数不对
请高手指点,谢谢,急盼!

解决方案 »

  1.   

    Private Type SECURITY_ATTRIBUTES
            nLength As Long
            lpSecurityDescriptor As Long
            bInheritHandle As Long 
    End Type
    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
      

  2.   

    Dim sa As SECURITY_ATTRIBUTES
    Com1_h = CreateFile("com1", (GENERIC_READ Or GENERIC_WRITE), 0, sa, OPEN_EXISTING, O, 0)
      

  3.   

    http://download.csdn.net/source/1339593