Creating libraries?



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 26/08/2008 at 20:42, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   9+ 
    Platform:      Mac OSX  ; 
    Language(s) :     C++  ;

    ---------
    Howdy,

    I'm creating a library from the example in the SDK documentation on Creating libraries. I've compiled a separate plugin of the library, and now I'm including the public files in my plugin. The compile succeeded and it seems to work fine, but there were a couple of warnings in Xcode:

    > \> warning: invalid access to non-static data member 'MyFunctionlib::MyLibraryFuncition' of NULL object \> warning: (perhaps the 'offsetof' macro was used incorrectly \>

    The code in the test library is just copied and pasted from the SDK documentation. Are the warnings something I need to worry about?

    Adios,
    Cactus Dan



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 02/09/2008 at 16:29, xxxxxxxx wrote:

    Howdy,

    Any answer on these warnings?

    Adios,
    Cactus Dan



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 03/09/2008 at 01:01, xxxxxxxx wrote:

    Hi!

    Could you post a piece of code? The warning should have a line comment. That would be useful. I guess, the warning means the "LIBOFFSET" function was used incorrectly and a warning with a null pointer should worry everytime.

    Bye :)



  • 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



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 03/09/2008 at 07:29, xxxxxxxx wrote:

    Howdy,

    Well, the typo was me retyping the warning because I couldn't copy and paste it from the Build Results window. :o(

    The actual line of code the warning is referring to is this line:

    > \> MyFunctionLib\* flib = CheckMyFunctionLib(LIBOFFSET(MyFunctionLib, MyLibraryFunction)); \>

    Compiling the library module plugin works fine, no errors or warnings. It's when the public header and public .cpp files are included in another plugin's compile that I get the warnings. It compiles successfully with the message "Succeeded 3 warnings" at the bottom of the build window. One of the warnings is the warning about the api directory which the XCode migration documentation told us to ignore.

    The plugin and the library work fine.

    Here's what the library actually does:
    It's a simple function compiled in R10 that checks an object's layer visibility and returns TRUE or FALSE. It is then included in an R9 compile of my plugin so it can check an R10 layer's visibilty. So, to use the library function in my R9 compiled plugin, I simply do this:

    > \> Bool layerVisible = TRUE; \> if(GetC4DVersion() > 9999) layerVisible = MyLibraryFunction(doc,op); \>

    Everything seems to work fine, the R9 compiled plugin runs in R10 and successfully checks whether or not the layer is visable. :o)

    I'm just curious about those warnings.
    One thing I noticed is that in R10's c4d_library.h file, LIBOFFSET is defined like this:

    > \> #define LIBOFFSET(s,m)   (LONG)((VULONG)(&(((s \* )0)->m))) \>

    ... and in R9's c4d_library.h file, LIBOFFSET is defined like this:

    > \> #define LIBOFFSET(s,m)   (VLONG)&(((s \* )0)->m) \>

    Could that have anything to do with it?

    Adios,
    Cactus Dan



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 04/09/2008 at 03:36, xxxxxxxx wrote:

    You can ignore these warnings. Also please switch off the warnings option in the target info, see picture below.

    cheers,
    Matthias



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 04/09/2008 at 05:37, xxxxxxxx wrote:

    Howdy,

    OK, thanks for the info. ;o)

    Adios,
    Cactus Dan


Log in to reply