Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Freaker13

sharing a static class between dll and exe

This topic is 5338 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, i''ve got a static lib as my renderer It contains interface classes for a dx dll and classes not implemented by dx. i''ve noticed that when is use a static log class in the implemented classes and not implemented class they do not share the log class but have their own copy. How can i share it between both? thx in advance

Share this post


Link to post
Share on other sites
Advertisement
Turn it into a singleton that uses dynamic allocation, and you should be fine.


"Sneftel is correct, if rather vulgar." --Flarelocke

Share this post


Link to post
Share on other sites
Every time I see someone mention singleton and DLL in the same post my toes curls and my joints crack. The fact of the matter is that most canned singleton implementations are not actually singletons in the presence of DLLs. Because of the joy of linking, most singleton implementations will give each copy of the DLL as well as the executable it''s own copy of the singleton, making it, by definition, not a singleton.

In order to properly share the log class, the instance of class must be exported properly. This can be done in several ways. Probably the cleanest method is to move the log class to it''s own separate DLL, export it''s functionality through normal DLL functions and link the your executable and your DLLs against that logging DLL.

Share this post


Link to post
Share on other sites
just use a global, like:

extern DLL_API CLog * g_Log;

define it in one cpp file:

CLog * g_Log = NULL;

i had never liked my singletons, and when i started using DLLs it gave me the final push i needed to get rid of them

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
the only way I really got static member data to work across DLL''s was using "real" shared memory (eg. using filemapping)

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!