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. C / C++ / MFC
  4. CMap question.

CMap question.

Scheduled Pinned Locked Moved C / C++ / MFC
questioncsharpvisual-studiodiscussion
3 Posts 2 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.
  • B Offline
    B Offline
    BarryPearlman
    wrote on last edited by
    #1

    Visual Studio 2010, Windows 7 645 bit. Objective: Create a CMap Object, store info and retrieve later. We have (out of context): typedef CMap<int, int, DWORD*, DWORD*> map_OpenObj; ........................................................................................ map_OpenObj* p_mapObj = NULL; p_map = new p_mapObj; ........................................................................................ nIdx = some integer; p_dwObj = (DWORD*)(pointer to some object); m_pOpenObjMap->SetAt(nIdx, p_dwObj); ....................................................................................... The above compiles, links and executes without incident with one exception. Later in the application I have: int nCount = 0; POSITION posPos = NULL; nCount = m_pOpenObjMap->GetCount(); posPOS = m_pOpenObjMap->GetStartPosition(); I get nCount = 1, which I would have expected, however posPOS comes back = 0xffffffff, which it shouldn't. This has worked before under Visual Studio 2008. Note: In the application, m_pOpenObjMap will never see ARG or ARG_KEY contain the same values. The question is what am I doing incorrectly? Any thoughts?

    Thanks, Barry

    C 1 Reply Last reply
    0
    • B BarryPearlman

      Visual Studio 2010, Windows 7 645 bit. Objective: Create a CMap Object, store info and retrieve later. We have (out of context): typedef CMap<int, int, DWORD*, DWORD*> map_OpenObj; ........................................................................................ map_OpenObj* p_mapObj = NULL; p_map = new p_mapObj; ........................................................................................ nIdx = some integer; p_dwObj = (DWORD*)(pointer to some object); m_pOpenObjMap->SetAt(nIdx, p_dwObj); ....................................................................................... The above compiles, links and executes without incident with one exception. Later in the application I have: int nCount = 0; POSITION posPos = NULL; nCount = m_pOpenObjMap->GetCount(); posPOS = m_pOpenObjMap->GetStartPosition(); I get nCount = 1, which I would have expected, however posPOS comes back = 0xffffffff, which it shouldn't. This has worked before under Visual Studio 2008. Note: In the application, m_pOpenObjMap will never see ARG or ARG_KEY contain the same values. The question is what am I doing incorrectly? Any thoughts?

      Thanks, Barry

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #2

      These words in the documentation[^]

      The iteration sequence is not predictable; therefore, the "first element in the map" has no special significance.

      look interesting. :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      B 1 Reply Last reply
      0
      • C CPallini

        These words in the documentation[^]

        The iteration sequence is not predictable; therefore, the "first element in the map" has no special significance.

        look interesting. :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

        B Offline
        B Offline
        BarryPearlman
        wrote on last edited by
        #3

        Please allow me to take this to the next level. The map is used to hold class pointers cast to (DWORD)*. When retrieved (CMap->Lookup(...)), they are cast back to theit original type and used. The number of elements at any given point in time in the map varies depending upon how many classes have been created or destroyed. When the application closes, the remaining map entries are cast back to their original pointers then deleted; the map is then destroyed. Obviously, if I just destroy the map, I am left with memory leaks of varying classes. The question occurs when I am down to just one map entry and it is time to close the application and destroy the last pointer cast DWORD*. How do I retrieve the last remaining item in the map?

        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