Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. ATL / WTL / STL
  4. std::list problem using dll

std::list problem using dll

Scheduled Pinned Locked Moved ATL / WTL / STL
help
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    Wim Jans
    wrote on last edited by
    #1

    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 dll int 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

    N M 2 Replies Last reply
    0
    • W Wim Jans

      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 dll int 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

      N Offline
      N Offline
      Nemanja Trifunovic
      wrote on last edited by
      #2

      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.

      W 1 Reply Last reply
      0
      • N Nemanja Trifunovic

        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.

        W Offline
        W Offline
        Wim Jans
        wrote on last edited by
        #3

        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

        N 1 Reply Last reply
        0
        • W Wim Jans

          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 dll int 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

          M Offline
          M Offline
          Michael Dunn
          wrote on last edited by
          #4

          The 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.

          1 Reply Last reply
          0
          • W Wim Jans

            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

            N Offline
            N Offline
            Nemanja Trifunovic
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups