i have an exe loading a dll. i wrote both.
i am dllexporting a function foo that returns a std::wstring.
all it does is say
std::wstring blah = L”rgjwgfw”;
return blah.append(L"hey");
in the exe where i import foo, the string is corrupt. as soon as i return from the function where i call foo i get failed assertions. sometimes i get a message saying Windows has triggered a breakpoint in foo.exe. this may be due to a corruption of the heap, etc….. This may also be due to a user pressing f12 while foo.exe has focus. etc….
any idea why this happens? it doesn’t happen if i remove the append line from foo and jsut return the original string, there are no problems.
thanks
This is pretty common problem. You need to link both the DLL and the executable to use the standard library in a DLL. That way they share a common copy of the standard library a common heap. Otherwise, you end up with code in the executable trying to use one heap, and code in the DLL using a separate heap. When you pass almost anything that uses dynamic allocation across the boundary, each assumes the dynamically allocated buffer in the object came from its own heap. Almost any manipulation can not only corrupt the object, but also the entire heap.