其他分享
首页 > 其他分享> > c-在Mac VBA的Office中调用dylib函数

c-在Mac VBA的Office中调用dylib函数

作者:互联网

我正在尝试从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

上面的应该可以工作(以相同的方式,遥控器应该完全位于您离开的位置).
但是显然我一定做错了,欢迎任何指向哪里的指示(越明显,越暗越好).

解决方法:

成功! (嗯,一直在那儿吗?)

This tutorial简要介绍了从VBA调用.dylib函数的基础.

只要确保install Xcode Command-Line Tools可用,您就可以使用nm命令从库中获取符号.

标签:dylib,c,macos,vba
来源: https://codeday.me/bug/20191012/1903692.html