VBA COM互操作麻烦

时间:2013-05-20 11:25:16

标签: c++ vba com

我有一些来自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互操作服务时指出我的错误。

1 个答案:

答案 0 :(得分:1)

代码是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无关。这是从外部库调用函数。

相关问题