Advertisement Jump to content


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

PsyCHo puNk

Need help with Object-Oriented DLL

This topic is 6399 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''m trying to create a DLL which is basically a set of reusable classes but I''ve run into a problem: /* Abstract base class */ class __declspec(dllexport) A { protected: // Data public: A(); virtual ~A(); // Pure virtual functions follow. virtual void somefunc(void) = 0; }; class __declspec(dllexport) B : public A { private: // Data public: B(); virtual ~B(); void somefunc(void); }; Conceptually B derives from abstract base class A. It compiles fine. I link it to the .lib file and place the .dll in the same directory as the client application exe but when I try this: A* test = NULL; test = new B(); delete test; or this: B* test = NULL; test = new B(); delete test; It results in: Debug Assertion failure File: dbgheap.c expression: _pFirstBlock == pHead Please let me know what I''m doing wrong.

Share this post

Link to post
Share on other sites
Wild guess [although it is 4:08am here and I''ve not been to bed yet]...

the DLL is built with a different version of the C Runtime library - if you''re expecting to do things which allocate memory in one module and call constructors with that memory in another module, you''d better make sure their allocators tally.

The best plan is to make both the DLL and EXE use the single or multithreaded DLL version of the CRT.

Or alternatively don''t try exposing complete classes through a DLL (its something I personally think is a bit nasty, and is also very compiler and language specific). A nicer way (YMMV) is to have an object create and destroy call in the DLL which the client calls [CSomeObject* MakeAnObject()] - or take a look at how (and why) COM does stuff [language, compiler and platform independence]

Simon O''''Connor
Creative Asylum Ltd

Share this post

Link to post
Share on other sites
Well, the way I would do it is to have One class in the DLL and have it''s prototype in the EXE

Then simply build a function in the DLL to pass a pointer to that Class.

So you have,

CInterface* g_pInterface;

Hope this helps.

Share this post

Link to post
Share on other sites
My goal is eventually to make it into a COM DLL however I figured it would be best to first learn how to create a normal windows DLL. I had it working with one class before but once I added the derived classes I started getting that debug assertion failure. I think COM would work very well in this case but after looking at all the other stuff associated with making it COM compliant... :-\ I''ll get around to that eventually but for now I still want to just get this set of classes working. I''m actually trying to set the design up like this:
class A is the abstract base class with a few methods that are common to all the derived classes and a few which must be implemented by the derived classes. The derived classes are actually the platform specific (Win32, Linux) classes (they share the common base class A but each have their own platform specific code. Using preprocessor directives it compiles the correct classes and produces the desired output (in windows a DLL, not sure about Linux yet since someone else is suppose to code it). Anyways if anyone figures out the problem, let me know and meanwhile I''ll hack away at it and see if I can find a solution.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!