There is a difference between
class CTestClass { public: _declspec(dllexport) CTestClass() {} _declspec(dllexport) virtual ~CTestClass() {} };
and
__declspec(dllexport) class CTestClass { public: CTestClass() {} virtual ~CTestClass() {} };
In the first case, you instructed the compiler to export only two member functions: CTestClass :: CTestClass () and CTestClass :: ~ CTestClass (). But in the latter case, you ask the compiler to also export the virtual function table. This table is required if you have a virtual destructor. So this could be the cause of the crash. When your program tries to call a virtual destructor, it looks for it in the linked table of virtual functions, but it is not initialized correctly, so we do not know where it actually points. If your destructor is not virtual, you do not need a table of virtual functions, and everything works fine.
source share