VBA COM interop烦恼 [英] VBA COM interop troubles

查看:240
本文介绍了VBA COM interop烦恼的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些MSDN的示例代码,我试图适应使用,但VBA编译器拒绝尖括号< > 。我在一个模块中有以下代码:

I have some sample code from MSDN that I am trying to adapt for use but the VBA compiler rejects the contents of the angled brackets < >. I have the following code in a module:

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

I am trying to use this code to call a simple function from a C++ dll that expects an array of strings but I get the compile error 'expected line number or label or statement or end of statement' and do not find the help menu provided to be any use. I have tried square brackets [ ] in case this is a problem of VBA version to no avail. Could someone point out my error in using the COM interop services.

推荐答案

代码是VB.NET。这不是VBA。

The code is VB.NET. This is not VBA.

在VBA中,你会写:

Declare Function Test Lib "../../insert_dll_name_here.dll" (file() As String) As Long

$然而,VBA不直接支持 cdecl 约定,但您可以使其与类型库配合使用。你也可能有麻烦与 file()As String 数组 - 确保在C ++端正确处理。

However, VBA does not directly support the cdecl convention, but you can make it work with a type library. You may also have troubles with the file() As String array - make sure to handle it properly on the C++ side.

另一方面,这与COM无关。这是从外部库调用函数。

As a side note, this has nothing to do with COM. This is calling a function from an external library.

这篇关于VBA COM interop烦恼的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆