I admit that this question sounds quite general. But after all, exporting classes from DLLs is a general and difficult topic, and frankly, I am currently confused on a quite general level.
The short question: How do object-oriented programming in C++ and DLLs fit together?
The long question: After reading this and this, I was slightly disappointed and confused because I wonder how object-oriented programming can work with DLLs if the DLL borders do not allow objects to be shared (assuming that two DLLs have used different compilers or compiler versions). The only options for exporting classes are these (as explained here or here):
- export create and delete methods (C style, danger of dangling pointers, no objects as parameters, ugly)
- export a pure virtual class and a factory function which creates an instance of the actual implementation class derived from the pure virtual class (needs inheritance, object deletion needs to be taken care of)
For example, I'd like to put common utility classes in one DLL, which I then use in several classes in other DLLs, which are themselves used in other DLLs. How can I do this? Is this an ill-defined way to organize my classes?
Bonus question: If I export a class having a pointer to implementation, is this equivalent to exporting a pure virtual class and a factory function? Or do the exported member functions have to be virtual?
EDIT: If it matters, I am on Windows 7 using Visual Studio 2010. Migrating vom an older Visual Studio made me sensitive to this problem.