Learn how to a build a cloud-first strategyRegister Now


Unhandled Exception on ProcessShellCommand()

Posted on 2006-05-17
Medium Priority
Last Modified: 2013-11-20
My MFC app urps on startup with an:
"Unhandled Exception.at 0x7823eafb (mfc80d.dll).in MyApp.exe. 0xC0000005: Access violation reading location 0xfdfe3f55".

I need some help finding out why this occurs or some advice on how to find/fix the problem. It worked until I converted it from VC++ 6 to Visual Studio 2005, but now fails in both IDE's.

The error appears during MyApp startup when ProcessShellCommand() is called from within InitInstance(). The cmdinfo structure sends a 'FileNew' command with an empty document name and the framework goes to work building the Doc and the View (SDIDoc app). Debugging shows the error occurs during the part where the framework is trying to create the main window. More specifically, it looks like during the window creation a handle to something cannot be obtained.

The stack trace looks like:
- mfc80d.dll!CMapPtrToPtr::GetValueAt(void * key=0x000a05c4)  Line 188 + 0x9 bytes
- mfc80d.dll!CHandleMap::LookupPermanent(void * h=0x000a05c4)  Line 114 + 0x16 bytes
- mfc80d.dll!CWnd::FromHandlePermanent(HWND__ * hWnd=0x000a05c4)  Line 321 + 0xc bytes
- mfc80d.dll!_AfxCbtFilterHook(int code=3, unsigned int wParam=656836, long lParam=1241572)  Line 525 + 0x9 bytes
<<a bunch of calls to user32.dll and ntdll.dll delete here for brevity>>
- mfc80d.dll!AfxCtxCreateWindowExA(unsigned long dwExStyle=512, const char * lpClassName=0x006a1800, const char * lpWindowName=0x003acf20, unsigned long dwStyle=550436864, int X=238, int Y=0, int nWidth=923, int nHeight=1022, HWND__ * hWndParent=0x00000000, HMENU__ * hMenu=0x008f02e3, HINSTANCE__ * hInstance=0x00400000, void * lpParam=0x0012f9c8)  Line 438 + 0xa1 bytes
- mfc80d.dll!CWnd::CreateEx(unsigned long dwExStyle=0, const char * lpszClassName=0x00000000, const char * lpszWindowName=0x003acf20, unsigned long dwStyle=13598720, int x=-2147483648, int y=-2147483648, int nWidth=-2147483648, int nHeight=-2147483648, HWND__ * hWndParent=0x00000000, HMENU__ * nIDorHMenu=0x008f02e3, void * lpParam=0x0012f9c8)  Line 694 + 0x35 bytes
- mfc80d.dll!CFrameWnd::Create(const char * lpszClassName=0x00000000, const char * lpszWindowName=0x003acf20, unsigned long dwStyle=13598720, const tagRECT & rect={...}, CWnd * pParentWnd=0x00000000, const char * lpszMenuName=0x00000080, unsigned long dwExStyle=0, CCreateContext * pContext=0x0012f9c8)  Line 560 + 0x54 bytes
- mfc80d.dll!CFrameWnd::LoadFrame(unsigned int nIDResource=128, unsigned long dwDefaultStyle=13598720, CWnd * pParentWnd=0x00000000, CCreateContext * pContext=0x0012f9c8)  Line 692 + 0x35 bytes
- mfc80d.dll!CDocTemplate::CreateNewFrame(CDocument * pDoc=0x01450040, CFrameWnd * pOther=0x00000000)  Line 277 + 0x22 bytes
- mfc80d.dll!CSingleDocTemplate::OpenDocumentFile(const char * lpszPathName=0x00000000, int bMakeVisible=1)  Line 125 + 0x13 bytes
- mfc80d.dll!CDocManager::OnFileNew()  Line 848
- mfc80d.dll!CWinApp::OnFileNew()  Line 22
- mfc80d.dll!CWinApp::ProcessShellCommand(CCommandLineInfo & rCmdInfo={...})  Line 26

The actual exception occurs within CMapPtrToPtr::GetValue in the for loop. GetValue() looks like:

void* CMapPtrToPtr::GetValueAt(void* key) const
// find value (or return NULL -- NULL values not different as a result)

      if (m_pHashTable == NULL)
            return NULL;

      UINT nHash = HashKey(key) % m_nHashTableSize;

      // see if it exists
      CAssoc* pAssoc;
      for (pAssoc = m_pHashTable[nHash]; pAssoc != NULL; pAssoc = pAssoc->pNext)  //<--- *** error occurs here ***
            if (pAssoc->key == key)
                  return pAssoc->value;
      return NULL;

The value of m_pHashTable is 0xFDFDFDFD. Isn’t that the value used for a freed long pointer?
m_nHasTableSize is also 0xFDFDFDFD (4261281277) and the resultant nHash is 36950. It seems like the hash table is invalid at this point hence the error.

Question by:dnewtontx

Author Comment

ID: 16728110
I found the answer.

After adding the following code it worked:

      // InitCommonControlsEx() is required on Windows XP if an application
      // manifest specifies use of ComCtl32.dll version 6 or later to enable
      // visual styles.  Otherwise, any window creation will fail.
      InitCtrls.dwSize = sizeof(InitCtrls);
      // Set this to include all the common control classes you want to use
      // in your application.
      InitCtrls.dwICC = ICC_WIN95_CLASSES;

This was added to my InitInstance().

Accepted Solution

EE_AutoDeleter earned 0 total points
ID: 16866863
Because you have presented a solution to your own problem which may be helpful to future searches, this question is now PAQed and your points have been refunded.


Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question