【问题标题】:Calling dylib functions in Office for Mac VBA在 Office for Mac VBA 中调用 dylib 函数
【发布时间】:2014-03-18 05:10:50
【问题描述】:

我正在尝试从简单的 Word for Mac 宏中调用存储在简单 dylib 文件中的简单函数,

我在 OS-X Mountain Lion 上使用 Xcode5 创建 .dylib,并从 Word for Mac 2011 中调用它。

首先是libWord.dylib:

Test.h

#ifndef __Word__Test__
#define __Word__Test__

bool testFunc();

#endif

Test.cpp

#include "Test.h"

bool testFunc(){
    return true;
}

和宏:

字宏

Private Declare Function testFunc Lib "/Users/usrName/Documents/libWord.dylib" () As Boolean

Sub TestLibFunc()

    Dim b As Boolean
    b = testFunc
    StatusBar = b

End Sub

宏可以找到dylib(我已经放在上面的目录中了),但是一直抛出:

“运行时错误‘453’: 找不到指定的 DLL 函数”

我也尝试过将函数声明为类的一部分:

class testClass{
    static bool testFunc();
}

bool testClass::testFunc(){
    return true;
}

然后尝试使用上面的 Declare 语句和一个别名来调用它:

Private Declare Function testFunc Lib "/Users/usrName/Documents/libWord.dylib" Alias "testClass::testFunc" () As Boolean

我还尝试将库路径名中的“/”替换为“:”,所有这些都给出了相同的结果。

那么,我错过了什么?就我所见过的所有例子而言:

VBA Shell function in Office 2011 for Mac

Return string to VBA in MacOSX

http://social.msdn.microsoft.com/Forums/en-US/b060f291-0754-4e85-a7b9-e64259e6baad/vba-using-shared-library-office-2011-mac?forum=isvvba

上述应该工作(以同样的方式遥控器应该就在你离开它的地方)。 但显然我一定做错了什么,任何关于在哪里看的指针都会受到欢迎(越明显和羞耻越好)。

【问题讨论】:

    标签: c++ macos vba dylib


    【解决方案1】:

    我怀疑最简单的方法是包装你的函数声明,而不是查找损坏的名称:

    extern "C" {
    bool testFunc();
    }
    

    【讨论】:

      【解决方案2】:

      成功! (呃,它一直在那里?)

      This tutorial 简洁地介绍了从 VBA 调用 .dylib 函数的基础知识。

      请务必install Xcode Command-Line Tools,以便您可以使用 nm 命令从库中获取符号。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-09-02
        • 1970-01-01
        • 2011-05-05
        • 1970-01-01
        • 2018-03-05
        • 2020-08-13
        • 1970-01-01
        • 2019-04-04
        相关资源
        最近更新 更多