Share via


Can't debug "Access violation reading location 0xcccccccc"

Question

Thursday, June 17, 2010 8:49 PM

Hello all.  I hope this message finds you well.

I'm writing a C++ exe that uses a C++ dll that I'm also writing.  Suddenly, with a function I just added, I'm getting the error "Access violation reading location..." when my exe calls the new function in the dll -- specifically at the line "return Device.GetMode( ModeNum, ModeVal );".  Putting a breakpoint in the dll and running it under debug mode doesn't help because the breakpoint says "The breakpoint will not currently be hit.  No symbols have been loaded for this document."

What's really strange is that calling this function is only a problem some of the time.  It's overloaded, and it's fine when it's getting a variable.  I only get the error the second time it's run, when it's setting a variable.  I did this after several frustrating days of convincing myself that the above error wasn't from the function not being found.

Using a trace function, I was able to determine that my function isn't even being called before the program crashes.  However, just in case, here's the dll function:

int __stdcall GetMode ( const int ModeNum, const bool ModeVal )
{
    
  CHECKAPI ( GetMode );
    
    if ( ModeNum == 0 ) {

        m_iMode = 0;

        Send ( "M\r" );

        return m_iMode;

    } else {

        _snprintf ( Buffer, sizeof(Buffer), "M,%d,%d\r", ModeNum, (ModeVal ? 1 : 0 ) );

        if ( !Send ( Buffer ) )
            return 0;

        return ModeNum;

    }

}

Thank you in advance.

All replies (7)

Saturday, June 19, 2010 3:29 PM ✅Answered | 1 vote

"Access violation reading location...", always means there is a invalid handle or pointer in your application. if the value is 0xcccccccc, means the pointer is called before it have a valid value(not be initialized).0xBAADF00D


Saturday, June 19, 2010 4:50 PM ✅Answered | 1 vote

What if the directory already has a pdb of the same name?

Then either the debugger or the executable is not referencing that same pdb/dll.

Sometimes it is easier to get the debugger set up correctly by opening the DLL project, and setting the breakpoint there. Then set Configuration Properties,Debugging,Command to the executable that needs to be launched.


Tuesday, June 22, 2010 1:50 AM ✅Answered

if you want to get the bug, you must have the source code to debug.

otherwise, you should make sure the calling of the function in  DLL is correct, then ask the DLL's author.

0xBAADF00D


Thursday, June 17, 2010 9:17 PM | 1 vote

One strong possibility is that the variable "Device" contains garbage.

It's easier obviously to troubleshoot if you use the debugger. Make sure the DLL is built in DEBUG mode, and that the generated PDB file is in the same directory as the DLL that is picked up by the EXE.


Friday, June 18, 2010 12:54 PM

Thanks for your prompt response.

What if the directory already has a pdb of the same name?


Monday, June 21, 2010 1:03 PM

So, the function works fine when it gets the value, but then when it sets the value, it's not initialized?  How do I track this?


Monday, June 21, 2010 1:08 PM

So you know, Brian, I did try setting the breakpoint in the DLL and setting the Configuration Properties,Debugging,Command to the executable that needs to be launched.  My breakpoint turned into a red ring with an error message that said "The breakpoint will not currently be hit.  No symbols have been loaded for this document."