THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 03/09/2008 at 03:57, xxxxxxxx wrote:
I don't know about these warnings but you may have a typo in there
'MyFunctionlib::MyLibraryFuncition'
Anyway I found also some typos/erros in the SDK docu so here are the corrected files for the function and the class library.
The function library
> \> //myfunctionlibrary.h \> \> #include "c4d.h" \> \> \> Bool MyLibraryFunction(LONG v, String s); \> \> \> // INTERNAL \> #define MY_UNIQUE_FUNCTION_LIBRARY_ID 1022950 \> \> struct MyFunctionLib : public C4DLibrary \> { \> Bool (\*MyLibraryFunction)(LONG v, String s); \> }; \> // INTERNAL \>
> \> //myfunctionlibrary.cpp \> \> #include "myfunctionlibrary.h" \> \> \> MyFunctionLib\* flib_cache = NULL; \> \> MyFunctionLib\* CheckMyFunctionLib(LONG offset) \> { \> return (MyFunctionLib\* ) CheckLib(MY_UNIQUE_FUNCTION_LIBRARY_ID, offset, (C4DLibrary\*\* ) &flib;\_cache); \> } \> \> Bool MyLibraryFunction(LONG v, String s) \> { \> MyFunctionLib\* flib = CheckMyFunctionLib(LIBOFFSET(MyFunctionLib, MyLibraryFunction)); \> if (!flib || !flib->MyLibraryFunction) return FALSE; \> \> return flib->MyLibraryFunction(v, s); \> } \>
> \> //myfunctionlibrarymodule.cpp \> \> #include "myfunctionlibrary.h" \> \> \> Bool iMyLibraryFunction(LONG v, String s) \> { \> GePrint("v: " + LongToString(v) + ", s: " + s); \> return v != 42; \> } \> \> \> MyFunctionLib flib; \> \> Bool RegisterMyFunctionLib() \> { \> // Clear the structure \> ClearMem(&flib;, sizeof(flib)); \> \> // Fill in all function pointers \> flib.MyLibraryFunction = iMyLibraryFunction; \> \> // Install the library \> return InstallLibrary(MY_UNIQUE_FUNCTION_LIBRARY_ID, &flib;, 1000, sizeof(flib)); \> } \>
The class library
> \> //mylibrary.h \> \> #include "c4d.h" \> \> \> class My1DVector \> { \> public: \> Real GetX() const; \> void SetX(Real x); \> \> static My1DVector\* Alloc(); \> static void Free(My1DVector\*& p); \> }; \> \> \> // INTERNAL \> \> #define MY_1D_VECTOR_LIBRARY_ID 1022949 \> \> class iMy1DVector; \> \> struct My1DVectorLib : public C4DLibrary \> { \> Real (iMy1DVector::\*GetX)() const; \> void (iMy1DVector::\*SetX)(Real x); \> \> iMy1DVector\* (\*Alloc)(); \> void (\*Free)(iMy1DVector\*& p); \> }; \> // INTERNAL \>
> \> //mylibrary.cpp \> \> #include "mylibrary.h" \> \> \> My1DVectorLib\* vlib_cache = NULL; \> \> My1DVectorLib\* CheckMy1DVectorLib(LONG offset) \> { \> return (My1DVectorLib\* ) CheckLib(MY_1D_VECTOR_LIBRARY_ID, offset, (C4DLibrary\*\* ) &vlib;\_cache); \> } \> \> \> Real My1DVector::GetX() const \> { \> My1DVectorLib\* vlib = CheckMy1DVectorLib(LIBOFFSET(My1DVectorLib, GetX)); \> if (!vlib || !vlib->GetX) return FALSE; \> \> return (((iMy1DVector\* )this)->\*(vlib->GetX))(); \> } \> \> void My1DVector::SetX(Real x) \> { \> My1DVectorLib\* vlib = CheckMy1DVectorLib(LIBOFFSET(My1DVectorLib, SetX)); \> if (!vlib || !vlib->SetX) return; \> \> (((iMy1DVector\* )this)->\*(vlib->SetX))(x); \> } \> \> My1DVector\* My1DVector::Alloc() \> { \> My1DVectorLib\* vlib = CheckMy1DVectorLib(LIBOFFSET(My1DVectorLib, Alloc)); \> if (!vlib || !vlib->Alloc) return NULL; \> \> return (My1DVector\* ) vlib->Alloc(); \> } \> \> void My1DVector::Free(My1DVector\*& p) \> { \> My1DVectorLib\* vlib = CheckMy1DVectorLib(LIBOFFSET(My1DVectorLib, Free)); \> if (!vlib || !vlib->Free) return; \> \> iMy1DVector\* tmp = (iMy1DVector\* ) p; \> vlib->Free(tmp); \> p = NULL; \> } \>
> \> //mylibrarymodule.cpp \> \> #include "mylibrary.h" \> \> \> class iMy1DVector \> { \> private: \> Vector v; \> \> public: \> Real GetX() const { return v.x; } \> void SetX(Real x) { v.x = x; } \> \> static iMy1DVector\* Alloc() { return gNew iMy1DVector; } \> static void Free(iMy1DVector\*& p) { gDelete(p); } \> }; \> \> \> My1DVectorLib vlib; \> \> Bool RegisterMy1DVectorLib() \> { \> // Clear the structure \> ClearMem(&vlib;, sizeof(vlib)); \> \> // Fill in all function pointers \> vlib.GetX = &iMy1DVector;::GetX; \> vlib.SetX = &iMy1DVector;::SetX; \> \> vlib.Alloc = iMy1DVector::Alloc; \> vlib.Free = iMy1DVector::Free; \> \> // Install the library \> return InstallLibrary(MY_1D_VECTOR_LIBRARY_ID, &vlib;, 1000, sizeof(vlib)); \> } \>
The corrected files compile without warnings for me on PC and Mac.
cheers,
Matthias