On 08/09/2014 at 07:14, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 13+
Platform: Windows ; Mac ; Mac OSX ;
Language(s) : C++ ;
---------
Hi,
I have created a class library as described in the docs. It seems to work, the library is correctly registered, an external library call even correctly jumps into the correct member function of the original library module (verified via debugging and via debug print outs). BUT the data does not seem to be valid (or corrupted).
One of the returned data is of simple integer type and returns how many objects of a certain type is available in the current document. I print out this value from within the library module itself as well as when my other project triggers the corresponding call. The library module returns 1 (correct) but the external call to the library returns 0 every time.
Trying to retrieve a class data member (instead of a simple integer type) even results in a crash (I created another class library for that custom type as well). It seems the pointer is not valid (but how could it jump into the correct member function then?)
What could cause these non-valid data? Did I do something wrong? Has anybody successfully tried this? Is the namespace a problem?
Thanks
Here is some pseudo code:
//Hook that needs to be exposed
class MyHook : public SceneHookData
{
private: int value;
public: int get_value() const { return value; } //Correctly jumping in here but value returns 0 although it should be 1
}
Bool RegisterHookLib()
{
ClearMem(&hooklib, sizeof(hooklib));
hooklib.get_value = &MyHook::get_value;
return InstallLibrary(LIBID, &hooklib, 1000, sizeof(hooklib));
}
//In the library file
namespace TESTLIB
{
class MyHook_mirror : public BaseSceneHook
{
private: MyHook_mirror(); ~MyHook_mirror();
public: int get_value() const //This implementation is actually in a cpp
{
MyHookLib *lib = CheckHookLib(LIBOFFSET(MyHookLib , get_value));
if (!lib || !lib->get_value) return NULL;
return (((MyHook* )this)->*(lib->get_value))();
}
};
//INTERNAL
struct MyHookLib : public C4DLibrary
{
int (MyHook::*get_value)() const;
}
}
Btw. this is how I call this:
MyHook_mirror* hookihook = static_cast<MyHook_mirror*>(doc->FindSceneHook(HOOK_ID));
if(!hookihook || hookihook->GetType() != HOOK_ID){ GePrint("Hook not found");} else GePrint(LongToString(hookihook->get_value())); //this get_value call correctly jumps into MyHook::get_value()!