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