none
Attempted to read or write protected memory. This is often an indication that other memory is corrupt. RRS feed

  • Question

  • I have been struggling with this problem for the past 4 working days. My C# application is calling functions in a c-dll.

    The location of the C dll is known at runtime so the dll is dynamically loaded.

     

     

    {

    tempDll = path of the C-dll

    try

    {

    pDll = LoadLibrary(tempDll);

    }

    catch

    {

    }

    if (pDll == IntPtr.Zero)

    throw new Exception("Cannot load library.");

    }

     

    I subsequently call functions from this dll. The problem is, somewhere along the line, I get the error

     

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

     

    The info in the output window is

     

    A first chance exception of type 'System.AccessViolationException' occurred in System.Windows.Forms.dll

    A first chance exception of type 'System.AccessViolationException' occurred in System.Windows.Forms.dll

    The program '[2496] ###: Managed' has exited with code 1073807364 (0x40010004).

     

    I understand that the problem can be attributed to making several read and write calls using a bad pointer. I suspect this could be true because the error occurs after I have called a particular function several times (like 70).

     

    How do I debug this problem? How do I find out if a pointer is a bad pointer?

    Tuesday, April 8, 2008 9:11 AM

Answers