Static data in a Class

I've run into something strange (at least strange to me with my limited Windows experience)...

If my plugin DLL contains a class with static data, everything links fine but Daz Studio fails to load the DLL. If I instead put the static data into a function in an anonymous namespace, the DLL loads fine.

Can anyone explain why? In any case, this is just a note to document the behavior (the Daz Studio error log is not helpful) in case someone else decides to use some class data and then suddenly their plugin won't load...

Comments

  • westechiewestechie Posts: 17

    If you use a DLL as a plugin, then it should probably go straight into the appropriate folder of your software install.  It should NOT go into My Documents or similar.  For instance, I put BreastJig_2.dll into my C:/Program Files/DAZ 3D/DAZStudio4/plugins/ folder.  Hopefully, this helps you.

  • westechie said:

    If you use a DLL as a plugin, then it should probably go straight into the appropriate folder of your software install.  It should NOT go into My Documents or similar.  For instance, I put BreastJig_2.dll into my C:/Program Files/DAZ 3D/DAZStudio4/plugins/ folder.  Hopefully, this helps you.

    Hi.

    It did go into the plugins folder. The only difference between a DLL that loads and a DLL that doesn't is that the one that doesn't has something like:

    plugin.cpp:

    int Plugin::staticMember = 0;

    plugin.h:

    class Plugin {
    ...
    static int staticMember;
    ...
    };
  • westechiewestechie Posts: 17
    edited April 2020

    It would be hard to say with out looking at source code.  I have not looked at the DAZ Studio 4.5 SDK yet.  Static constants usually are meant to always load from the beginning of an app, and they only leave as the application closes down.  A plugin usually extends the purpose of software, and DAZ Studio seems to only load and un-load plugins.

    Perhaps totally avoiding the use of static constants would be the best route for you to go.  Those really never work well in plugins any how, unless you are the primary developer of some thing.  Even then, things with statics tend to gradually become part of the main program because of how they must only load and un-load, when the program it self does.

    Post edited by westechie on
  • TheMysteryIsThePointTheMysteryIsThePoint Posts: 1,654
    edited April 2020

    Found the issue. It's either a bug in the Daz Studio sample code I copied, or I somehow deleted the -DDZ_MAKEDLL as in the code below, from dzgeneraldefs.h:

    #    ifdef DZ_MAKEDLL // Create a DLL library
    #        define DZ_EXPORT __declspec(dllexport)
    #    else    // Use a DLL library
    #        define DZ_EXPORT __declspec(dllimport)
    #    endif
    Post edited by TheMysteryIsThePoint on
Sign In or Register to comment.