Share heap between DLL's
I have a quite large project written originally in BC5, and I am
currently porting it to Visual C++ (VS2005) using OWLNext
(www.owlnext.com).
The program itself is now "converted", and it is running, but with
errors.
The error that concerns me the most is that I get heap error when
trying this simple thing:
1) Creating a char*
2) Setting this char* to a new duplicate of another char* - this is
done in another DLL.
3) Deleting this char*
Example code:
void ParseLine(char* line)
{
char* xNumStr;
xNumStr = strnewdup(line);
delete[] xNumStr;
}
strnewdup is a part of OWL (and owl-dll) and goes like this:
strnewdup(const char* s, size_t allocSize)
{
if (!s)
s = "";
int alloc = max(strlen(s)+1, allocSize);
return strcpy(new char[alloc], s);
}
It's the delete[] in ParseLine that gives the error, which states that
the heap is corrupt (I am running in debug-mode).
If I move the strcpy-call from owl-dll to within ParseLine code, I get
no error.
This code works in BC5, but not in VC. I suspect it has to do with the
heap being private for each DLL, but I'm not sure. If I need to change
the code, I have to do it hundredths of places, and I really do not
want to do that.
Can anyone tell me why this error occurs, and maybe help me with how
to fix it without changing the code too much?!?