vbacom互操作问题

VBA COM interop troubles

本文关键字:问题 互操作 vbacom      更新时间:2023-10-16

我有一些来自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约定,但您可以使其与类型库一起工作。你也可能会遇到file() As String数组的问题-确保在c++端正确处理它。

作为旁注,这与COM无关。这是从外部库调用函数。