Jump to content
  • Advertisement
Sign in to follow this  
Simplicity

DLL and STL

This topic is 4574 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

I ran into this avoiding problem with DLL and STL. Consider: DLL1: class A { std::map< int, int > Map; }; A* Create() { //This is psuedo, assumes it dynamically loads DLL2 and get the function // pointer to the CreateB function declared in DLL2 (CREATE*)pfn = LoadDLL(DLL2)-GetSymbol("CreateB"); return( pfn() ); } DLL2: class B : public A { void Init() { Map[0] = 50; } }; A* CreateB() { return( new B() ); } DLL2 has a class derived from DLL1 and link at compile time. EXE: //Link to DLL1 at compile time A a = Create(); //Create from DLL1 //This cause some weird heap error that tooked several hours to figured out. delete a; The problem was that std::map< int, int > Map didn't carry over properly or something. If I remove that from class A and place it in class B, everything is ok. How to solve this problem?

Share this post


Link to post
Share on other sites
Advertisement
You shouldnt create something in DLL B and delete it in your exe. Preferably you should make a Destroy() function which will delete the object in the DLL it was created in.

Also, ensure that both DLLs and the exe make use of a dynamic C/C++ runtime.

Share this post


Link to post
Share on other sites
Ok so I make the proper Create and Destroy functions from the DLL. I still cannot properly derive from the class within a different DLL.

Share this post


Link to post
Share on other sites
You can probably solve the problem if you make every function in the base class virtual and never use the constructors between DLLs...

(and suddenly, you begin to re-invent COM)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!