Skip to main content
gamedev.net
🔒 Locked

DLL classes

Started by fyhuang 4 replies 300+ views
Original Post
fyhuang
fyhuang
I''m making a DLL with MVC++ 6.0, and I am trying to use STL containers (std::list) inside my DLL interface classes, and the compiler doesn''t seem to like that... how can I use ''non-DLL-interface'' classes inside DLL-interface classes?
- fyhuang [ site ]
SiCrane
SiCrane
Templates and DLLs really don''t don''t mix that well. It would be better to refactor your code so that the std::list member is not exposed through the DLL interface.

However, you might want to take a look a this link regarding your specific problem.
fyhuang
fyhuang
Yeah, I figured that out a while ago...

However, I don''t want to write my own container class either. The article you mentioned said that several STL containers (std::list) were not exportable. It also mentioned that the templated class must be instianted first... does that mean that I have to create a ''dummy'' variable for each possible value!?!

Augh... or I could use void *, but that''s really bad...
- fyhuang [ site ]
SiCrane
SiCrane
As I said, the prefered solution is to refactor your code. One way is to define an interface class with the functionality you desire that exposes none of it''s implementation, and have the DLL return a pointer to a derived class rather than the original class. Alternately you can emply pimpl, etc.

As for the instantiation questions, instantiation doesn''t necessarily mean declaring a variable of the template type (though that is one way to cause instantation). The instantiation method mentioned in that article is the via the
EXPIMP_TEMPLATE template class DECLSPECIFIER std::vector<MyClass>; line in the source code. This line declares that the code for the class should be generated and exported from the DLL.
markr
markr
Why does it have to be a .DLL ? Can''t it just be a static library?

Mark
fyhuang
fyhuang
Wow, I never thought of that! How can you change the project settings to make the linker make a static library instead of a DLL?

Thanks for all your help!
- fyhuang [ site ]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.