std::list problem using dll
-
Hello, In my application I call a dll, which contains an exported class. The class has a member function, which passes a std::list by reference. When using the push_back member of the list, the application just freezes after a few iterations: In my main app:
std::list< std::basic_string > m_Columns; int bReturn=pMyDllClass->doit(m_Columns);
In my dllint CMyDllClass::doit(std::list< std::basic_string >& out) { ... for (int n=0; n<20; n++) { out.push_back(std::basic_string("test"); } ... return 0; // <== never reached }
After iteration 11 or so, the app freezes. I I use this piece of code in my main app, so not using the dll but using a normal class, it works perfectly. Any idea what I'm doing wrong Thanks Regards Wim -
Hello, In my application I call a dll, which contains an exported class. The class has a member function, which passes a std::list by reference. When using the push_back member of the list, the application just freezes after a few iterations: In my main app:
std::list< std::basic_string > m_Columns; int bReturn=pMyDllClass->doit(m_Columns);
In my dllint CMyDllClass::doit(std::list< std::basic_string >& out) { ... for (int n=0; n<20; n++) { out.push_back(std::basic_string("test"); } ... return 0; // <== never reached }
After iteration 11 or so, the app freezes. I I use this piece of code in my main app, so not using the dll but using a normal class, it works perfectly. Any idea what I'm doing wrong Thanks Regards WimI see two potential problems here: 1. You may be using VC6. In that case you need to either patch your STL, or use STLPort in order to pass STL objects accross DLL boundaries. 2. You are statically linking CRT and C++ Standard library. If you are doing this, than you should better delete objects in the same dll where they are created.
-
I see two potential problems here: 1. You may be using VC6. In that case you need to either patch your STL, or use STLPort in order to pass STL objects accross DLL boundaries. 2. You are statically linking CRT and C++ Standard library. If you are doing this, than you should better delete objects in the same dll where they are created.
Hello, Thanks for your reply. 1) I'm using Visual C++.NET 2003, with latest sdk's. 2) I've set the 'Minimize CRT usage in ATL' to No. I'm not using atl for the dll anyway... If I should delete my objects in the dll I'm using, how can I do that? After all, I'm passing the std::list reference from my main program to the dll. The dll is just stuffing the std::list with data... Regards Wim
-
Hello, In my application I call a dll, which contains an exported class. The class has a member function, which passes a std::list by reference. When using the push_back member of the list, the application just freezes after a few iterations: In my main app:
std::list< std::basic_string > m_Columns; int bReturn=pMyDllClass->doit(m_Columns);
In my dllint CMyDllClass::doit(std::list< std::basic_string >& out) { ... for (int n=0; n<20; n++) { out.push_back(std::basic_string("test"); } ... return 0; // <== never reached }
After iteration 11 or so, the app freezes. I I use this piece of code in my main app, so not using the dll but using a normal class, it works perfectly. Any idea what I'm doing wrong Thanks Regards WimThe app and the DLL must both be linking to the DLL version of the CRT for that to work. If one (or both) use the static LIB version, each will have a different heap, and one cannot alloc/free on the other's heap. --Mike-- Personal stuff:: Ericahist | Homepage Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ ---- There is a saying in statistics that a million monkeys pounding on typewriters would eventually create a work of Shakespeare. Thanks to the Internet, we now know that this is not true.
-
Hello, Thanks for your reply. 1) I'm using Visual C++.NET 2003, with latest sdk's. 2) I've set the 'Minimize CRT usage in ATL' to No. I'm not using atl for the dll anyway... If I should delete my objects in the dll I'm using, how can I do that? After all, I'm passing the std::list reference from my main program to the dll. The dll is just stuffing the std::list with data... Regards Wim
Wim Jans wrote: After all, I'm passing the std::list reference from my main program to the dll. The dll is just stuffing the std::list with data... "Just stuffing" is the problem. That's because you allocate the data you "stuff" in one module (dll), and delete it in the second one (exe). Arguably the easiest way to get around this problem is to follow Michael Dunn's advice.