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
Could it be that the string A::getString() returns is being allocated in A.dll and freed in main.exe?
Yes.
If so, why - and what would be a safe way to pass strings between DLLs (or executables, for that matter)? Without using wrappers like shared_ptr with a custom deleter.
Using a shared_ptr
sounds like a sensible thing to me. Remember, as a rule of thumb, allocations and deallocations should be done by the same module to avoid glitches like these.
Exporting STL objects across dlls is at best a tricky pony. I suggest you check out this MSDN KB article first and this post.