我有一些来自 MSDN 的示例代码,我正在尝试对其进行改编以供使用,但 VBA 编译器拒绝尖括号 < >
中的内容.我在模块中有以下代码:
Imports System
Imports System.Runtime.InteropServices
<DllImport("../../insert_dll_name_here.dll", CallingConvention:=CallingConvention.Cdecl)> _
Public Function Test(file() As String) As Integer
End Function
我正在尝试使用这段代码从 C++ dll 中调用一个简单的函数,该函数需要一个字符串数组,但我收到编译错误“预期的行号或标签或语句或语句结尾”并且没有找到帮助提供的菜单可任意使用。我试过方括号 [ ]
万一这是VBA版本的问题无济于事。有人可以指出我在使用 COM 互操作服务时的错误。
最佳答案
代码是VB.NET。这不是 VBA。
在 VBA 中你会写,
Declare Function Test Lib "../../insert_dll_name_here.dll" (file() As String) As Long
但是,VBA 不直接支持cdecl
约定,但您可以make it work with a type library .您可能还会遇到 file() As String
数组的问题 - 请确保在 C++ 端正确处理它。
作为旁注,这与 COM 无关。这是从外部库调用函数。
关于c++ - VBA COM 互操作问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16648447/