7

我使用从 Adob​​e Reader 9 安装中获取的 axAcroPDFLib 控件在我的 C# 窗口表单应用程序中显示和打印用户 PDF 文档。一切正常,直到应用程序关闭...

它抛出以下错误:

“0x0700609c”处的指令引用了“0x00000014”处的内存。无法读取内存

我的 FormClosing 方法很简单,我认为是错误的,但我不知道如何以正确的方式做到这一点:

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

        }
    }

提前感谢您的任何想法

4

1 回答 1

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

于 2009-08-31T22:29:27.770 回答