我想在 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() 在 VB6 中已经是红色,表明存在错误)。这与“RunMotor1 (200, 50, 0, 0)”相同。
看起来我的转换不太好...
最佳答案
VB.Net Integer
是 32 位,但 VB6 Integer
是 16 位,在 VB6 Long
中是 32 位类型,因此使用在你的声明中。
InitStp ()
语法无效,请删除括号并单独使用 InitStp
- 但这会忽略返回值,这通常不是一个好主意,因此:
Dim result as Long
result = InitStp()
关于dll - "Compile Error Syntax error"调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47431427/