System Access Error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • 4Codehelp
    New Member
    • Jul 2007
    • 3

    System Access Error

    I have a code in VC++ that gives this particular error on exiting the program while executing in release mode.

    Error:
    An unhandled exception of type 'System.AccessV iolationExcepti on' occurred in Unknown Module.

    Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

    The execution breaks at one of these places:

    1. file name oleinit.cpp
    [code=cpp]
    if (pThread != NULL)
    {
    // destroy message filter (may be derived class)
    delete pThread->m_pMessageFilt er;
    pThread->m_pMessageFilt er = NULL; // This is the line where execution breaks
    }[/code]

    2. File name cmdtarg.cpp
    [code=cpp]
    CCmdTarget::~CC mdTarget()

    {

    #ifndef _AFX_NO_OLE_SUP PORT

    if (m_xDispatch.m_ vtbl != 0)

    ((COleDispatchI mpl*)&m_xDispat ch)->Disconnect() ; //This is the line where error is indicated

    ASSERT(m_dwRef <= 1);

    #endif

    m_pModuleState = NULL;

    }
    [/code]
    The same doesnot happen when i execute the program in debug mode. Also when i execute the program throught the executable the exiting doesnot give this error. Can someone please help.
    Last edited by sicarie; Jul 11 '07, 01:16 PM. Reason: Please use [code=cpp] and [/code] tags around your code.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    This code:
    Originally posted by 4Codehelp
    if (pThread != NULL)
    {
    // destroy message filter (may be derived class)
    delete pThread->m_pMessageFilt er;
    pThread->m_pMessageFilt er = NULL; // This is the line where execution breaks
    }
    Do you know that m_pMessageFilte r points at a heap allocation??

    Most likely, the code is breaking on the delete.

    Comment

    • 4Codehelp
      New Member
      • Jul 2007
      • 3

      #3
      Originally posted by weaknessforcats
      This code:


      Do you know that m_pMessageFilte r points at a heap allocation??

      Most likely, the code is breaking on the delete.

      Hi

      Thanks for the reply. I get this error only when i am executing the code through the development environment in release mode. The problem doesnot arise when i use the exe file directly....

      Is it possible that I am using some memory used by the envt itself?

      Kind regards

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        Originally posted by 4CodeHelp
        ((COleDispatchI mpl*)&m_xDispat ch)->Disconnect() ; //This is the line where error is indicated
        You are certain that m_xDispatch is, in fact, a COleDispatchImp l object???

        Why not use a C++ cast that is not the meatax of the C cast?

        Maybe:
        [code=cpp]
        COleDisparchImp l* rval = static_cast<COl eDisparchImpl*> (&m_xDispatch );
        [/code]

        and see it that compiles. No run time check but better than a C cast.

        Then I would enable RTTI and try:

        [code=cpp]
        COleDisparchImp l* rval = dynamic_cast<CO leDisparchImpl* > (&m_xDispatch );
        if (!rval)
        {
        //you have a problem
        return; //bail
        }
        rval->Disconnect() ;
        [/code]

        Comment

        Working...