實際上,我正在玩接口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
很完善的功能。