Sign in to follow this  

DLL and STL

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

This topic is 4356 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this