Pregunta

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).

¿Fue útil?

Solución 2

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.

Otros consejos

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

extern "C" {
bool testFunc();
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top