实际上,我正在玩接口c/C++和Excel-2011 for mac的VBA。我怎么能在dylib中设计以指针为参数或引用的函数?或数组?甚至是简单的结构?在windows下,VARIANT
让我来做所有事情,但是我不能在OS X(甚至是Linux下)下使用它。传递c/C++ dylib函数将指针指向VBA上的指针
正如评论,到现在为止,我可以(包括“简单”型)做这样的事情:
我有下面的代码配置:在tmp3class.h:
class TheClass
{
public:
double mysum(double x ,double y);
};
在tmp3class.cpp:
#include "./tmp3class.h"
double TheClass::mysum(double x ,double y)
{
return x+y ;
}
和tmp3.cpp:
#include "./tmp3class.h"
extern "C"
{
double THESUM(double x, double y)
{
TheClass TheObj ;
double res = TheObj.mysum(x,y);
return res ;
}
}
我编译这个用:
g++-5.2.0 -m32 -Wall -g -c ./tmp3class.cpp -o ./tmp3obj.o
g++-5.2.0 -m32 -dynamiclib .tmp3.cpp ./tmp3obj.o -o ./tmp3.dylib
,然后在VBA我这样做:
Declare Function THESUM Lib "/Users/XXXXXX/Documents/GITHUBRepos/DYLIBS/MyFirstDylib/tmp3.dylib" (ByVal x As Double, ByVal y As Double) As Double
Function THESUM_VBA(x As Double, y As Double) As Double
THESUM_VBA = THESUM(x, y)
End Function
和THESUM_VBA
很完善的功能。