2009-08-31 91 views
7

Im使用从Adobe Reader 9安装中取得的axAcroPDFLib控件在我的C#窗体表单应用程序中显示和打印用户PDF文档。一切都运行得很好,直到该器件的应用密切...axAcroPDFLib在关闭问题C#

它引发以下错误:

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

我的FormClosing方法是相当简单的,我认为是错误的,但我不知道该怎么做以正确的方式:

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

     } 
    } 

先感谢您的任何想法

回答

11

我只是想出了如何正确地关闭应用程序:

[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(); 
     } 
    } 

这一点,不会引发错误:d

+0

好极了,好找!我一直在努力争取一段时间,你在哪里找到答案? – Siyfion 2010-01-11 09:54:19

+0

我不记得我在哪里找到它... 在一个丢失的网站中,我发现了一个类似的错误使用Office 2003的一个DLL。我看到了相似之处,并将相同的解决方案应用于我的问题,并且工作。 但在此之前,我浪费了周。 – Hector 2010-02-03 19:25:00

+0

这不行!它挂在axAcroPDF1.Dispose(); – 2017-02-22 17:57:48