vb 串口
請教各位先進,我有一個程式為兩端互傳資料,但在call ftfunc副程式時,會產生沒有定義錯誤,我將其g_buftab()定義成long or byte,皆會產生另一api錯誤訊息,請教原因或解決方式,為何?以下是副程式部份!!!
Public Const gmem_fixed = &H0
Declare Function globalalloc Lib "kernel32" (ByVal wflags As Long, ByVal dwbytes As Long) As Long
Declare Function globallock Lib "kernel32" (ByVal hmem As Long) As Long
Declare Function globalfree Lib "kernel32" (ByVal hmem As Long) As Long
Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" (ByVal lpstring As Long) As Long
Declare Function lstrcpyn Lib "kernel32" Alias "lstrcpynA" (ByVal lpString1 As String, ByVal lpString2 As Long, ByVal iMaxLength As Long) As Long
Public Function xcallback(ByVal xmitlen As Long, ByVal buflen As Long, ByVal buf As Long, ByVal flen As Long) As Long
On Error Resume Next
DoEvents
Call Form1.Refreshstate(xmitlen, flen, gxfname)
xcallback = 0
End Function
Public Function rcallback(ByVal recvlen As Long, ByVal buflen As Long, ByVal buf As Long, ByVal flen As Long) As Long
On Error Resume Next
DoEvents
Call lstrcpn(grfname, g_buftab(0), lstrlen(g_buftab(0)) + 1)
DoEvents
Form1.Text1 = App.Path & "\" & grfname
Call Form1.Refreshstate(recvlen, flen, grfname)
rcallback = 0
End Function
Public Sub ftfunc(port As Long, direction As Integer)
Dim ret As Long
If (direction = 0) Then
ret = sio_FtZmodemTx(port, grfname, AddressOf xcallback, 27)
Else
g_buftab(0) = globallock(globalalloc(gmem_fixed, max_path + 1))
Call lstrcpy(g_buftab(0), "")
End If
If ret < 0 Then
MsgBox "傳送/接收失敗", vbCritical + vbOKOnly, "warming"
Else
If (direction = 0) Then
MsgBox "傳送完成", vbInformation + vbOKOnly, "Send_message"
Else
MsgBox "接收完成", vbInformation + vbOKOnly, "Receive_message"
End If
End If
End Sub
页:
[1]