(Mac)将字符串从VBA传递到Dylib-在C 函数中接收到的空字符串

(Mac) Passing string args from VBA to dylib - empty string received in C++ function

本文关键字:字符串 函数 Dylib- Mac VBA      更新时间:2023-10-16

试图从VBA调用C 函数(以Dylib的汇编),然后将字符串传递给其如下 -

.h

extern "C"
{
int func(const char* &str);
}

.cpp

int func(const char* &str)
{
//something something
}

vba

Declare PtrSafe Function func Lib "<LibPath>" (ByRef str As String) As Integer
...
Function outFunc
   Dim str As String
   str = "Hello"
   func (str)
End Function

在调试C 代码时,该函数被正确点击,但是在" str"变量中接收到空字符串。还使用NM实用程序来确认该函数已从Dylib正确暴露。

我认为您的函数参数的类型不正确。我认为,如果将C参数更改为const char* str并将其定义为ByVal str As String,则它将起作用。

请参阅https://www.codeproject.com/articles/810282/microsoft-office-vba-t-to-the-macs