class in dll, deleting pointer

Started by
2 comments, last by Venire 20 years, 9 months ago
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....
--Venire/PASTel^dBeast^Hc3
Advertisement
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
Brian J
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 ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
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.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara

This topic is closed to new replies.

Advertisement