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. Permanent Handle Map problem

Permanent Handle Map problem

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestiondelphidata-structureslearning
4 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.
  • E Offline
    E Offline
    Electronic75
    wrote on last edited by
    #1

    Hello, I have a view that has a property sheet and property pages. when I want start a new document an assertion error happens. I followed the call stack and found out that problem occurs at this function

    CWnd* PASCAL CWnd::FromHandlePermanent(HWND hWnd)
    {
    CHandleMap* pMap = afxMapHWND();
    CWnd* pWnd = NULL;
    if (pMap != NULL)
    {
    // only look in the permanent map - does no allocations
    pWnd = (CWnd*)pMap->LookupPermanent(hWnd);
    ASSERT(pWnd == NULL || pWnd->m_hWnd == hWnd);//<<<< this ASSERT fails
    }
    return pWnd;
    }

    I took the hWnd and searched it in spy++ windows list and I found out that this window is the property sheet. In spy++ I couldn't find any problem in properties of this window even its childs(property pages) seemed OK. but the problem is when windows look in its permanent handle map it returns an erroneous pointer. the pointer is not null neither the hWnd of the returned pointer but hWnd of returned pointer is 0x30203020 which is different from the FromHandlePermanent(HWND hWnd) supplied sane handle. of course the returned pointer is completely erroneous and this supposed to be a window has no sane owner, child, next window or prev window. How can I find the problem? thanks

    M 1 Reply Last reply
    0
    • E Electronic75

      Hello, I have a view that has a property sheet and property pages. when I want start a new document an assertion error happens. I followed the call stack and found out that problem occurs at this function

      CWnd* PASCAL CWnd::FromHandlePermanent(HWND hWnd)
      {
      CHandleMap* pMap = afxMapHWND();
      CWnd* pWnd = NULL;
      if (pMap != NULL)
      {
      // only look in the permanent map - does no allocations
      pWnd = (CWnd*)pMap->LookupPermanent(hWnd);
      ASSERT(pWnd == NULL || pWnd->m_hWnd == hWnd);//<<<< this ASSERT fails
      }
      return pWnd;
      }

      I took the hWnd and searched it in spy++ windows list and I found out that this window is the property sheet. In spy++ I couldn't find any problem in properties of this window even its childs(property pages) seemed OK. but the problem is when windows look in its permanent handle map it returns an erroneous pointer. the pointer is not null neither the hWnd of the returned pointer but hWnd of returned pointer is 0x30203020 which is different from the FromHandlePermanent(HWND hWnd) supplied sane handle. of course the returned pointer is completely erroneous and this supposed to be a window has no sane owner, child, next window or prev window. How can I find the problem? thanks

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      Electronic75 wrote:

      I followed the call stack and found out that problem occurs at this function

      Is this on a different thread than the thread the window was created on?

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      E 2 Replies Last reply
      0
      • M Mark Salsbery

        Electronic75 wrote:

        I followed the call stack and found out that problem occurs at this function

        Is this on a different thread than the thread the window was created on?

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        E Offline
        E Offline
        Electronic75
        wrote on last edited by
        #3

        Hello Mark, No it is in the same thread. I followed the stack more closely and with the help of a lot of breaking points and many hours I found out problem occurs in an XML class that tries to read an XML file. I have a MFC application and I used a MSXML wrapper class from this address http://www.codeguru.com/cpp/data/data-misc/xml/article.php/c8287/[^] (I don't know credit of this work goes to whom I later found out some people developed very similar codes earlier). Now I already had defined a pointer to my CPropertySheet in my CDocument class m_pDefineSheet = new CDefineSheet; and when I open a new document a new view is created and the property sheet will be created as its child

        CFormView::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);

        pDoc = (CMyoc*) GetDocument();
        if(!pDoc)
        return 0;

        pDoc->m\_pDefineSheet->AddPage(pDoc->m\_pDev1);
        pDoc->m\_pDefineSheet->AddPage(pDoc->m\_pDev2);
        pDoc->m\_pDefineSheet->AddPage(pDoc->m\_pDev3);	
        
        
        if (!pDoc->m\_pDefineSheet->Create(this,
        		DS\_CONTEXTHELP | DS\_SETFONT | WS\_CHILD | WS\_VISIBLE))
        {
        	DestroyWindow();
        	return FALSE;
        }      
        

        No problem thus far then CMyDoc::OnNewDocument()will be executed and there it loads an XML document using CXMLManager m_xmlManager

            m\_xmlManager.Initlize();
        m\_xmlManager.Load(sData);
        m\_xmlManager.GetRoot()->get\_childNodes(&pList1);
        n1 = m\_xmlManager.GetNoOfChilds(pList1) ;
        for(i1=0;i1<n1;i1++)>
        {
        	pNode1 = m\_xmlManager.GetItemNode(i1,pList1);
        	pList2 = m\_xmlManager.GetChildList(pNode1);
        	n2 = m\_xmlManager.GetNoOfChilds(pList2) ;
        	sName1 = m\_xmlManager.GetNodeName(pNode1);
        	sData = m\_xmlManager.GetText(pNode1);
             }
        

        Upon execution of this code it seems that something overwrites the m_pDefineSheet location and when I execute AfxGetMainWnd()->FromHandle((HWND)x) in immediate window x is the handle of m_pDefinesheet which was ok prior to execution of this code it returns error note that I receive no error of memory access violation that someone illegally has tried to write in memory This is first time I have encountered such problem! Thank you anyway.

        1 Reply Last reply
        0
        • M Mark Salsbery

          Electronic75 wrote:

          I followed the call stack and found out that problem occurs at this function

          Is this on a different thread than the thread the window was created on?

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          E Offline
          E Offline
          Electronic75
          wrote on last edited by
          #4

          Hi Mark, It took almost a day of my time but problem solved problem was in MSXML get_text when it tries to read a big chunk of data it was overwriting on m_pDefineSheet place so FromHandle() returned an erroneous address that already had been overwritten by evil get_text. One thing I still didn't understand is why windows wouldn't give a memory access violation error. cheers

          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