• Advertisement

Archived

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

Exporting Template Class From DLL

This topic is 5032 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've built my entire code base into a DLL file, but some of my classes derive from a templated singleton object (described in the Enginuity articles). Now, in my exe I create an instance of the derived class, like so: * EngineMode is a #define that gets switched between __declspec( dllexport ) and __declspec( dllimport ) for each project [in the DLL project] class EngineMode XShaderUtility : public XSingleton< XShaderUtility > [in EXE project] XShaderUtility* UtilityObject = new XShaderUtility; * UtilityObject is a valid object, and can be used XShaderUtility* UtilityObject2 = XShaderUtility::getPtr(); * UtilityObject2 should be equal to UtilityObject, but it results in an assertion, because XShaderUtility is an invalid singleton (?! we just initialized it above!) When compiling the DLL file in VC++ 6.0, I get the following warning: warning C4275: non dll-interface class 'XSingleton' used as base for dll-interface class 'XShaderUtility' But there's no way I can specify 'EngineMode' for XSingleton and get the warning to go away. To recap, my problem is that I cannot use my singleton objects in the EXE file when they are compiled in the DLL file. I suspect the above warning as the culprit, but any help would be appreciated. BTW, my EXE statically links to the DLL's library file, then at runtime it uses the DLL. [EDIT]: and I know the singleton class's code is bug-free, because I've used it before many, many times where everything is statically linked and it worked fine. Chris Pergrossi My Realm | "Good Morning, Dave" [edited by - c t o a n on April 14, 2004 10:54:54 AM]

Share this post


Link to post
Share on other sites
Advertisement
I think this article addresses your issue. Obviously, you need to substitute your singeton class template instantiation.

edit: btw, for your own peace of mind, if you try to mix DLLs, C++ classes and templates, I would recommend trying to isolate the implemenation details behind design firewalls. Ex: you don't really need to export the whole singleton class, just export a function that returns the singleton's instance.

[edited by - SiCrane on April 14, 2004 3:44:47 PM]

Share this post


Link to post
Share on other sites
Thanks SiCrane, for your response. I''ve modified my singleton code to adjust for the memory space differences when using my DLL file (because the EXE dynamically links to the DLL, then the DLL loads more DLL''s that dynamically link to it, etc.) and it works great! Thanks again

Chris Pergrossi
My Realm | "Good Morning, Dave"

Share this post


Link to post
Share on other sites

  • Advertisement