I am working on a Win32 c++ application in Visual studio.
In one of the source files, I have global object like below.
TestClass tObj;
int main() //Execution starts here
{
}
TestClass is defined in other DLL like below.
struct Source
{
};
class TestClass
{
list<Source> sourceList;
public:
TestClass() {}
~TestClass() {}
};
While my application is running, if i try to close the app explicitly, by closing the console window, it is crashing in TestClass destructor. Callstack shows CrtIsValidHeapPointer is failing.
Pls help me to solve this issue.
Your problem is that differing compiler/linker settings between the .exe and .dll are effectively causing the .dll and .exe to be using different implementations of the standard library:
To fix this, go to Project > Properties > Configuration Properties > C/C++ > Code Generation
and change the runtime library option to Multi-threaded Debug DLL (/MDd)
. You must do this for both the .exe project and the .dll project.
As of Visual Studio 2010, some of these kind of errors will be detected at link time using #pragma detect_mismatch.
*For all preprocessor flags that have any effect of the standard library implementation
Make sure you build bot the EXE and the DLL with the same runtime, preferably with the dynamic runtime.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With