我想在VB6中调用DLL,并且我在Visual Studio 2008中使用了代码(示例程序)。
====这是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, 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
====这是VB6代码====
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)”也是如此。
看起来我的转换不合适......
答案 0 :(得分:3)
VB.Net Integer
是32位,但VB6 Integer
是16位,在VB6中Long
是32位类型,所以在声明中使用它。
InitStp ()
语法无效,删除括号并自己拥有InitStp
- 但忽略返回值通常不是一个好主意,所以相反:
Dim result as Long
result = InitStp()
答案 1 :(得分:2)
无论发生什么其他情况,在VB6中,除非您还使用Sub
关键字,否则不应在Call
的参数周围使用括号。这同样适用于作为Function
调用的Sub
,换句话说:
RunMotor1 200, 50, 0, 0
- 或 -
Call RunMotor1 (200, 50, 0, 0)
但永远不会
RunMotor1 (200, 50, 0, 0)