• Advertisement


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

class in dll, deleting pointer

This topic is 5381 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! i have this tiny engine of mine, at it was a set of *.cpp files, each containing some class, i used them like this:
//at top

#include "cBaseClass.h"
cBaseClass* g_pBase=NULL;

//in main()

g_pBase = new cBaseClass();

//at the end

and it all worked fine, no matter hom crappy solution that is now, i want to convert my engine to one,big dll file, so i made this:
/////////////////////////in dll.cpp

#include "cBase.h"


///////////////////////////in dll.h

#ifdef LIB_EXP
#define LIB_API __declspec(dllexport)
#define LIB_API __declspec(dllimport)

class LIB_API cBase 
the problem is, that when i compile the exec with this lib, and use the same pointer_class->thing like in the first example i get debug assertion failure on some HeapChecking routine. I figure it out, that the problem is related to the fact that the class is new''ed in dll''s heap and deleted''ed in exe''s heap hmmm, i always thought that this is the same heap...whatever... i also tried all the combinations with CRT lib (MultiThreaded,Dll,etc....) so this isn''t my problem...i''ve just run out of ideas please help....

Share this post

Link to post
Share on other sites
Create a function in the DLL that calls delete on the object. Call that function instead of manually deleting the object from the exe.

[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]

Share this post

Link to post
Share on other sites
Dll''s get a seperate memory heap from the main program. If the object is allocated (via new) from code in the main program, it needs to be deleted there - and if it''s allocated in dll code, dll code needs to delete it.

Share this post

Link to post
Share on other sites

  • Advertisement