Calling dylib functions in Office for Mac VBA

拜拜、爱过 提交于 2019-12-02 07:11:02

问题


I am attempting to call a simple function that is stored in a simple dylib file, from a simple Word for Mac macro,

I'm creating the .dylib with Xcode5 on OS-X Mountain Lion, and calling it from Word for Mac 2011.

first the libWord.dylib:

Test.h

#ifndef __Word__Test__
#define __Word__Test__

bool testFunc();

#endif

Test.cpp

#include "Test.h"

bool testFunc(){
    return true;
}

and the macro:

Word Macro

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

Sub TestLibFunc()

    Dim b As Boolean
    b = testFunc
    StatusBar = b

End Sub

The Macro can find the dylib (which I have placed in the above directory), but keeps throwing:

"Run-time error '453': Specified DLL function not found"

I have also tried declaring the function as part of a class:

class testClass{
    static bool testFunc();
}

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

and then tried to call it using both the above Declare statement, and one with an alias:

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

I also tried replacing "/" with ":" in the library path name, all of which give the same result.

So, what am I missing? as far as all the examples I've seen go:

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

The above should work (in the same way the remote control should be exactly where you left it). but obviously I must be doing something wrong and any pointers as to where to look would be welcome (the more obvious and shaming the better).


回答1:


Success! (ugh, it was there the whole time?)

This tutorial succinctly covers the basics of calling .dylib functions from VBA.

Just be sure to install Xcode Command-Line Tools so that you can use the nm command to get the symbols from your library.




回答2:


Rather than looking up the mangled name, I suspect the easiest way is to wrap your function declarations:

extern "C" {
bool testFunc();
}


来源:https://stackoverflow.com/questions/22470863/calling-dylib-functions-in-office-for-mac-vba

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!