I have some trouble figuring out why the following crashes (MSVC9):
//// the following compiles to A.dll with release runtime linked dynamically
//A.h
class
You need to link to the same runtime lib (the DLL one), either debug or release, for every DLL in your app where memory is allocated in one and freed in another. (The reason for using the dynamically linked runtime lib is that then there will be one heap for your entire process, as opposed to one per dll/exe that links to the static one.)
This includes returning std::string and stl-containers by value, as that is what you do.
The reasons are twofold (updated section):
So, get your runtime libs straight, or stop freeing/allocating in different dlls (i.e. stop passing stuff by value).