7

Im using a axAcroPDFLib control taken from a Adobe Reader 9 installation to show and print user PDF documents within my C# window forms application. Everything works just fine untill the appication close...

It throws the following error:

The instruction at "0x0700609c" referenced memory at "0x00000014". The memory could not be read

My FormClosing method is quite simple and i think is wrong, but i didn't know how to do it in the right way:

private void Form2_FormClosing(object sender, FormClosingEventArgs e)
    {
        if (axAcroPDF1 != null)
        {   
            axAcroPDF1.Dispose();

        }
    }

thanks in advance for any idea

hecvd
  • 659
  • 1
  • 8
  • 24

1 Answers1

11

I just figured out how to close the application properly:

    [System.Runtime.InteropServices.DllImport("ole32.dll")]
    static extern void CoFreeUnusedLibraries();

    private void Form2_FormClosing(object sender, FormClosingEventArgs e)
    {
        if (axAcroPDF1 != null)
        {                                
            axAcroPDF1.Dispose();                
            System.Windows.Forms.Application.DoEvents();
            CoFreeUnusedLibraries(); 
        }
    }

with this, no error is thrown :D

hecvd
  • 659
  • 1
  • 8
  • 24
  • Fantastic, good find! I've been struggling with this for a while now, where did you find the answer? – Siyfion Jan 11 '10 at 09:54
  • i don't remember where i found it... In a lost website, i found a similar error using one dll of office 2003. I saw the resemblance and applied the same solution to my problem, and it worked. But before that, i wasted WEEKS. – hecvd Feb 03 '10 at 19:25
  • This does not work! it hangs on axAcroPDF1.Dispose(); – Carlo Bos Feb 22 '17 at 17:57
  • Maybe something changed in the last 7 years – hecvd Jul 13 '18 at 09:23