Archived

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

Venire

class in dll, deleting pointer

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

SAFEDELETE(g_pBase);
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"
cBase::cBase()
{
//etc....

}

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

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

class LIB_API cBase 
{
public:
	cLog();
};
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
Hey, I can''t directly help as I don''t really understand your problem- but this article gives an implementation for using classes with DLL''s...I bet you could learn something there.


Brian J
DL Vacuum - A media file organizer I made | Mumbling Miles - A band I was the guitarist/vocalist for

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