Re: Assistance required, exporting a class from a DLL
<morgan.s.reed@gmail.com> wrote:
Of course after I posted I found the solution...
The issue is now resolved, I needed to make all my interface
class virtual;
The code in the sample you mentioned is far from being complete.
You found one problem that interface methods are not virtual. Here
are additional problems:
1. The interface doesn't expose an explicit method for class
deletion but rather relies on `operator delete'. Using `operator
delete' with exported interface requires virtual destructor to be
declared in the interface.
2. Using `operator delete' with exported interface requires that
both EXE and DLL modules will link with the same version of CRT
library and link with it dynamically. Also, Debug/Release mode of
CRT must be synchronizes between the EXE and DLL.
In order to make robust DLL interface that you will able to call
from different clients you need to declare abstract class without
data members and with all member functions being pure virtual.
Also, you need to provide explicit member for deletion of class
instance (like IUnknown::Release, for example). Then instead of
calling `operator delete' with the interface you will call this
method.
You can find the more elaborate study here:
"HowTo: Export C++ classes from a DLL"
http://www.codeproject.com/KB/cpp/howto_export_cpp_classes.aspx
HTH
Alex