?
eigentlich beide Varianten (V1 und V2) bringen zum Ziel :
V1: "Makus_gast":
cpp:
extern "C"__declspec (dllexport) void* createWrapper(double a, double b)
{
return new MyClass(a,b);
}
extern "C"__declspec (dllexport) void destoryWrapper(void *instance)
{
delete static_cast<MyClass*>(instance);
}
extern "C"__declspec (dllexport) double Add(void *instance, double a, double b)
{
MyClass *myClass = static_cast<MyClass*>(instance);
return myClass->Add(a, b);
}
V2: DarkShadow44
cpp:
MyClass* staticMyClassObject;
extern "C"__declspec(dllexport) void createWrapper(double a, double b)
{
staticMyClassObject = new MyClass(a, b);
}
extern "C"__declspec(dllexport) void destoryWrapper()
{
delete staticMyClassObject;
}
extern "C"__declspec(dllexport) double Add(double a, double b)
{
return staticMyClassObject->Add(a, b);
}
@ Markus_gast:
Das Objekt kannst du auch jedes mal erzeugen in dem du so machst z.B:
--> für V1:
extern "C"__declspec (dllexport) double Add(void *instance, double a, double b)
{
MyClass *myClass = static_cast<MyClass*>(createWrapper(a,b));
return myClass->Add(a, b);
}
--> für V2:
extern "C"__declspec(dllexport) double Add(double a, double b)
{
createWrapper(a,b);
return staticMyClassObject->Add(a, b);
}
--> Die Frage ist: Welche der Varianten ist zu empfehlen ?