Dll &引用;编译错误语法错误“;调用函数
我想在VB6中调用一个DLL,我在VisualStudio2008中有工作代码(示例程序) ==这是Visual Studio 2008代码====Dll &引用;编译错误语法错误“;调用函数,dll,visual-studio-2008,vb6,Dll,Visual Studio 2008,Vb6,我想在VB6中调用一个DLL,我在VisualStudio2008中有工作代码(示例程序) ==这是Visual Studio 2008代码==== Declare Function InitStp Lib "stp.dll" () As Integer Declare Function RunMotor1 Lib "stp.dll" (ByVal steps As Integer, ByVal interval As Integer, ByVal direction As Integer, B
Declare Function InitStp Lib "stp.dll" () As Integer
Declare Function RunMotor1 Lib "stp.dll" (ByVal steps As Integer, ByVal interval As Integer, ByVal direction As Integer, ByVal outputs As Integer) As Boolean
Private Sub Command1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Stop1.Click
InitStp ()
End Sub
Private Sub Command2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Stop1.Click
RunMotor1 (200, 50, 0, 0)
End Sub
Private Declare Function InitStp Lib "stp.dll" () As Integer
Private Declare Function RunMotor1 Lib "stp.dll" (ByVal steps As Integer, ByVal interval As Integer, ByVal direction As Integer, ByVal outputs As Integer) As Boolean
Private Sub Command1_Click()
InitStp ()
End Sub
Private Sub Command2_Click()
RunMotor1 (200, 50, 0, 0)
End Sub
==这是VB6代码====
Declare Function InitStp Lib "stp.dll" () As Integer
Declare Function RunMotor1 Lib "stp.dll" (ByVal steps As Integer, ByVal interval As Integer, ByVal direction As Integer, ByVal outputs As Integer) As Boolean
Private Sub Command1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Stop1.Click
InitStp ()
End Sub
Private Sub Command2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Stop1.Click
RunMotor1 (200, 50, 0, 0)
End Sub
Private Declare Function InitStp Lib "stp.dll" () As Integer
Private Declare Function RunMotor1 Lib "stp.dll" (ByVal steps As Integer, ByVal interval As Integer, ByVal direction As Integer, ByVal outputs As Integer) As Boolean
Private Sub Command1_Click()
InitStp ()
End Sub
Private Sub Command2_Click()
RunMotor1 (200, 50, 0, 0)
End Sub
当我尝试运行InitStp()的代码时,我得到了“编译错误语法错误”(代码InitStp()在de VB6中已经是红色,表示存在错误)。这与“RunMotor1(200,50,0,0)”相同
看起来我的转换不正常…无论发生什么,在VB6中,您不应该在
子
的参数周围使用括号,除非您还使用调用
关键字。这适用于作为Sub
s调用的函数
s,换句话说:
RunMotor1 200, 50, 0, 0
--或--
但从来没有
RunMotor1 (200, 50, 0, 0)
VB.Net
Integer
是32位的,但是VB6Integer
是16位的,在VB6Long
中是32位的类型,所以在声明中使用它
InitStp ()
如果语法无效,请删除括号并单独使用InitStp
,但这样会忽略返回值,这通常不是一个好主意,因此:
Dim result as Long
result = InitStp()
谢谢,这很有效!现在的代码
Private Declare函数InitStp Lib“stp.dll”()只要Private Declare函数RunMotor1 Lib“stp.dll”(ByVal步长长,ByVal间隔长,ByVal方向长,ByVal输出长)只要Boolean Private Sub Command1_Click()调用InitStp End Sub Private Sub Command2_Click()调用RunMotor1(200,50,0,0)末端接头