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. Assistance with 0xC0000005: Access Violation

Assistance with 0xC0000005: Access Violation

Scheduled Pinned Locked Moved C / C++ / MFC
helpdebuggingtutorialquestion
7 Posts 5 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.
  • R Offline
    R Offline
    Reagan Conservative
    wrote on last edited by
    #1

    I am getting this error as soon as the program executes. It's a dialog-based application. In debug it takes me to the following source code: _AFXWIN_INLINE void CWnd::SetFont(CFont* pFont, BOOL bRedraw) { ASSERT(::IsWindow(m_hWnd)); ::SendMessage(m_hWnd, WM_SETFONT, (WPARAM)pFont->GetSafeHandle(), bRedraw); } Is this trying to tell me there is a bad handle in the ASSERT section, or a Font problem? Is there a tutorial that could help? Many thanks.

    John P.

    P H 2 Replies Last reply
    0
    • R Reagan Conservative

      I am getting this error as soon as the program executes. It's a dialog-based application. In debug it takes me to the following source code: _AFXWIN_INLINE void CWnd::SetFont(CFont* pFont, BOOL bRedraw) { ASSERT(::IsWindow(m_hWnd)); ::SendMessage(m_hWnd, WM_SETFONT, (WPARAM)pFont->GetSafeHandle(), bRedraw); } Is this trying to tell me there is a bad handle in the ASSERT section, or a Font problem? Is there a tutorial that could help? Many thanks.

      John P.

      P Offline
      P Offline
      prasad_som
      wrote on last edited by
      #2

      Probably, you are calling SetFont function on uninitialized CWnd object.


      Prasad MS MVP -  VC++

      R 1 Reply Last reply
      0
      • P prasad_som

        Probably, you are calling SetFont function on uninitialized CWnd object.


        Prasad MS MVP -  VC++

        R Offline
        R Offline
        Reagan Conservative
        wrote on last edited by
        #3

        I don't think that's the real problem. In this particular project, I've added a new dialog by copying and pasting the relevant parts of the dialog from the .RC and resource.h files. I've also added the .CPP and .H files for this dialog to the workspace. Plus the files I copied into the different project worked just fine in the old project from where they were copied. To me, this error just doesn't make sense. Is there anything else that could be the problem due to my copying and pasting from one project to another? Thanks again.

        John P.

        D 1 Reply Last reply
        0
        • R Reagan Conservative

          I don't think that's the real problem. In this particular project, I've added a new dialog by copying and pasting the relevant parts of the dialog from the .RC and resource.h files. I've also added the .CPP and .H files for this dialog to the workspace. Plus the files I copied into the different project worked just fine in the old project from where they were copied. To me, this error just doesn't make sense. Is there anything else that could be the problem due to my copying and pasting from one project to another? Thanks again.

          John P.

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          jparken wrote:

          I don't think that's the real problem.

          Actually, that IS the problem. Whatever control you are trying to set the font for has a NULL window handle. Check the call stack when that assertion fires to see where your code is in error.


          "A good athlete is the result of a good and worthy opponent." - David Crow

          "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

          R 1 Reply Last reply
          0
          • D David Crow

            jparken wrote:

            I don't think that's the real problem.

            Actually, that IS the problem. Whatever control you are trying to set the font for has a NULL window handle. Check the call stack when that assertion fires to see where your code is in error.


            "A good athlete is the result of a good and worthy opponent." - David Crow

            "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

            R Offline
            R Offline
            Reagan Conservative
            wrote on last edited by
            #5

            David --- I'm having a problem with the underlying logic then. If these same files do not have this problem in the other project (which is identical except for the addition of one new dialog), then why would this error appear in the one with the new dialog, which has not even been called by the system when it first loads up? Or does that not matter in a case like this? I'm going on the assumption that the problem is in the very first dialog that is being called at statrup of this .exe --- poor assumption on my part? Thanks

            John P.

            K 1 Reply Last reply
            0
            • R Reagan Conservative

              I am getting this error as soon as the program executes. It's a dialog-based application. In debug it takes me to the following source code: _AFXWIN_INLINE void CWnd::SetFont(CFont* pFont, BOOL bRedraw) { ASSERT(::IsWindow(m_hWnd)); ::SendMessage(m_hWnd, WM_SETFONT, (WPARAM)pFont->GetSafeHandle(), bRedraw); } Is this trying to tell me there is a bad handle in the ASSERT section, or a Font problem? Is there a tutorial that could help? Many thanks.

              John P.

              H Offline
              H Offline
              Hans Dietrich
              wrote on last edited by
              #6

              jparken wrote:

              Is there a tutorial that could help?

              When you're dealing with code that you're not familiar with, usually the fastest way to track down this type of problem is to run the app under the VS debugger, and then look at the stack to see how it got there. The code that you posted is somewhere within the MFC libraries. So what you need to do is to find out how you got there. The good news is that dialog-based apps are the simplest kind of MFC app. Do you see the dialog at all before the ASSERT error? If not, then there is a good chance that the dialog template in the RC file is incorrect or missing; or the IDD resource id in resource.h doesn't match what's in the RC file, or in the dialog's .h header file. Just make sure everything matches up - for dialog apps, it's pretty straightforward, and will fix this kind of problem 90% of the time. After making any changes, be sure to recompile everything, to make sure it's all in sync. Best wishes, Hans

              1 Reply Last reply
              0
              • R Reagan Conservative

                David --- I'm having a problem with the underlying logic then. If these same files do not have this problem in the other project (which is identical except for the addition of one new dialog), then why would this error appear in the one with the new dialog, which has not even been called by the system when it first loads up? Or does that not matter in a case like this? I'm going on the assumption that the problem is in the very first dialog that is being called at statrup of this .exe --- poor assumption on my part? Thanks

                John P.

                K Offline
                K Offline
                krmed
                wrote on last edited by
                #7

                One possible reason for this would be that when you copy files/resources from one project to another, the controls on the copied dialog may have the same resource id as other controls that you already have. Open your resource.h file and look for duplicate numbers for the resource IDs. If there are duplicates, renumber them to eliminate the duplicates, the completely rebuild your project. Hope that helps.

                Karl - WK5M PP-ASEL-IA (N43CS) PGP Key: 0xDB02E193 PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193

                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