Make sure both the DLL and the EXE are linked to the DLL runtime library
(msvcrt.dll or similar). If the EXE & DLL aren't both linked to the exact
same (debug/non-debug, compiler version, everything must match) runtime DLL,
you'll run into problems trying to pass std::string (and indeed any class
that holds memory allocated from the heap) between them.
If for some reason the two modules cannot use the same runtime library, then
you'll have to redesign so as to avoid passing strings across the DLL/EXE
boundary.
-cd
Quote:
> Basically here is my problem, I am returning a std::string which can
> be quite large from a dll to the exe. It works fine, until the
> std::string's dtor is called.
> In the following code, two strings are created in the dll (libbig.cpp)
> and returned to the exe (big.cpp). The good string destroys fine and
> behaves as expected. The bad string's dtor calls the "user breakpoint
> at 0xFOOBAR".
> So my question is, huh? And how do I fix this. Is this a known win32
> issue buried somewhere in the knowledge base?
> Thnx,
> Justin
> // libbig.h
> #ifdef LIBBIG_EXPORTS
> #define LIBBIG_API __declspec(dllexport)
> #else
> #define LIBBIG_API __declspec(dllimport)
> #endif
> #include <string>
> class LIBBIG_API Big
> {
> public:
> Big(){}
> std::string str(int sz, char c)const;
> };
> //libbig.cpp
> std::string Big::str(int sz, char c)const
> {
> std::string rv;
> for(int i=0;i<sz;++i){rv+=c;}
> return rv;
> }
> //big.cpp
> #include "../libbig/libbig.h"
> int main(int argc, char* argv[])
> {
> libbig::Big lbb;
> {
> std::string good = lbb.str(127,'A');
> }
> {
> std::string bad = lbb.str(128,'A');
> }
> return 0;
> }