I have a Windows DLL that at one point, returns a pointer to a class that is new'ed in the DLL's code. The class itself is a very thin wrapper around another class private to the DLL.
The calling executable has no problem working with this class, everything works fine, with the exception that when the calling executable tries to delete this class, I get a RtlValidateHeap error.
The reasons behind the error makes sense, the exe is trying to free memory on the DLL's heap, which is normally a bad thing.
I've come up with a few possible solutions:
- Override the class's new operator to allocate its memory off of the executable's heap (provided I can even get at that heap space). The wrapper is very thin, so I would only be allocating a few bytes from the exe's heap.
- Provide a special destruction function for this class (yuck).
- Tell the user not to destroy the class and live with leaks (no way!)
Is there a 'normal' way of doing this?