Unhandled Exception on ProcessShellCommand()

Posted on 2006-05-17
Last Modified: 2013-11-20
My MFC app urps on startup with an:
"Unhandled 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

    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

    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.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    Title # Comments Views Activity
    only14 challenge 19 57
    sumHeights  challenge 17 50
    noX challenge 17 53
    mapAB Challlenge 35 46
    Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
    Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
    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.
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

    761 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

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now