Deleting template class in dll makes runtime error

Started by
1 comment, last by EverIce 19 years, 7 months ago
I have a template class that worked well before exporting to dll. But after that it makes runtime error when calling destructor. It looks like :

template <class T>
class X
{
   *T mData;
   ~X()
  {
    if (mData)
    delete mData;
  }
};

Can you help me finding how could this be happened ?
Advertisement
mData is probably allocated in the exe. You can't allocate memory in the exe and deallocate it in the DLL (or vice-versa), because with the static linked CRT, the DLL and exe get different heaps. Free the memory from the exe, allocate it in the DLL, or use the DLL version of the CRT - but you'll have to make sure both apps link with the exact same version, i.e. You can't have one linked with the single threaded debug CRT and one with the multithreaded debug, and you can't mix debug/release versions and compiler versions.
Uh, that was fast, thanks.

But i don't get fully your suggestion.

"use the DLL version of the CRT " - it means that my app and my dll runtime library must be single-threaded debug ?

Otherwise i have to change the code ?

This topic is closed to new replies.

Advertisement