7

Adobe ActiveXコントロールを使用してPDFを表示するC#.NETアプリを作成しました。

これは、アプリケーションに付属しているいくつかのDLLに依存しています。これらのDLLは、ローカルにインストールされているAdobeAcrobatまたはマシンにインストールされているAdobeAcrobatReaderと相互作用します。

このアプリはすでに一部のお客様に使用されており、ほぼすべてのユーザーに最適です(ローカルマシンが少なくともバージョン9のAcrobatまたはReaderを実行していることを確認します)。

ロードしようとすると(ActiveXコントロールがロードされているときに)、アプリが「COMコンポーネントの呼び出しからエラーHRESULTE_FAILが返されました」というエラーメッセージを返す3つのケースを見つけました。

これらのユーザーのマシンの1つを確認しましたが、彼はAcrobat 9をインストールしており、問題なく頻繁に使用しています。Acrobat 9と一緒にレジストリにエントリがあるため、Acrobat7と8は一度にインストールされたようです。

この問題をローカルで再現することはできないため、どちらの方向に進むべきか正確にはわかりません。

スタックトレースの先頭にあるエラーは次のとおりです。System.Runtime.InteropServices.COMException(0x80004005):エラーHRESULTE_FAILがCOMコンポーネントの呼び出しから返されました。

このエラーに関するいくつかの調査は、それがレジストリの問題であることを示しています。

この問題を修正または回避する方法、または問題の根本的な原因に到達する方法を決定する方法について誰かが手がかりを持っていますか?

エラーメッセージの全内容は次のとおりです。

System.Runtime.InteropServices.COMException(0x80004005):エラーHRESULTE_FAILがCOMコンポーネントの呼び出しから返されました。System.Windows.Forms.UnsafeNativeMethods.CoCreateInstance(Guid&clsid、Object punkOuter、Int32 context、Guid&iid)at System.Windows.Forms.AxHost.CreateWithoutLicense(Guid clsid)at System.Windows.Forms.AxHost.CreateWithLicense(String license 、Guid clsid)at System.Windows.Forms.AxHost.CreateInstanceCore(Guid clsid)at System.Windows.Forms.AxHost.CreateInstance()at System.Windows.Forms.AxHost.GetOcxCreate()at System.Windows.Forms.AxHost .TransitionUpTo(Int32 state)at System.Windows.Forms.AxHost.CreateHandle()at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)atSystem.Windows.Forms.Control。

4

3 に答える 3

11

わかりました、私自身の質問に答えるために報告します。

この問題は、[設定]>[インターネット]の[ブラウザにPDFを表示する]の設定に直接関係していました。このオプションをオンにすると、問題は解決します。チェックを外すと戻ってきます。

プログラムで処理する方法は次のとおりです。

    private string defaultPdfProg()
    { //Returns the default program for opening a .pdf file; On Fail returns empty string. 
      // (see notes below) 
        string retval = "";

        RegistryKey pdfDefault = Registry.ClassesRoot.OpenSubKey(".pdf").OpenSubKey("OpenWithList");
        string[] progs = pdfDefault.GetSubKeyNames();
        if (progs.Length > 0)
        {
            retval = progs[1];
            string[] pieces = retval.Split('.'); // Remove .exe

            if (pieces.Length > 0)
            {
                retval = pieces[0];
            }
        }

        return retval;
    }

    private void browserIntegration(string defaultPdfProgram)
    { //Test if browser integration is enabled for Adobe Acrobat (see notes below)
        RegistryKey reader = null;
        string[] vers = null;

        if (defaultPdfProgram.ToLower() == "acrobat")
        { //Default program is Adobe Acrobat
            reader = Registry.LocalMachine.OpenSubKey("Software").OpenSubKey("Adobe").OpenSubKey("Adobe Acrobat");
            vers = reader.GetSubKeyNames();
        }
        else if (defaultPdfProgram.ToLower() == "acrord32")
        { //Default program is Adobe Acrobat Reader
            reader = Registry.LocalMachine.OpenSubKey("Software").OpenSubKey("Adobe").OpenSubKey("Acrobat Reader");
            vers = reader.GetSubKeyNames();
        }
        else
        {
            //TODO: Handle non - adobe .pdf default program
        }

        if (vers.Length > 0)
        {
            string versNum = vers[vers.Length - 1].ToString();
            reader = reader.OpenSubKey(versNum);
            reader = reader.OpenSubKey("AdobeViewer",true);

            Boolean keyExists = false;
            Double keyValue = -1;
            foreach(string adobeViewerValue in reader.GetValueNames())
            {
                if (adobeViewerValue.Contains("BrowserIntegration"))
                {
                    keyExists = true;
                    keyValue = Double.Parse(reader.GetValue("BrowserIntegration").ToString());
                }
            }

            if (keyExists == false || keyValue < 1)
            {
                string message = "This application requires a setting in Adobe to be changed. Would you like to attempt to change this setting automatically?";
                DialogResult createKey = MessageBox.Show(message, "Adobe Settings", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
                if (createKey.ToString() == "OK")
                {
                    reader.SetValue("BrowserIntegration", 1, RegistryValueKind.DWord);
                    //test to make sure registry value was set
                }
                if (createKey.ToString() == "Cancel")
                {
                    //TODO: Provide instructions to manually change setting
                }
            }
        }
    }

注意すべきいくつかの項目:

これらの場所がすべてのバージョンで交換可能かどうか、または特定のバージョンのAcrobatに基づいてレジストリキーが異なる場所にあるかどうかを誰かが知っていますか?ReaderはAcrobatと同じロジックに従いますか?

  • アドビは、Windowsファイルの関連付け以外の「PDFファイルを開くためのデフォルトのアドビアプリケーション」を決定するために他の方法を使用していますか?FoxItなどの非adobe製品がデフォルトのファイル関連付けアプリケーションとしてインストールされているが、ReaderとAcrobatの両方がインストールされているマシンでAdobeのActiveXコントロールを使用している場合、どのロジックを使用してどのアプリケーションを決定するかを尋ねます。 COMオブジェクトは通信しますか?
于 2010-04-01T16:30:59.503 に答える
1

私のシステム(Windows XP、Adobe Reader 9.3.2)の場合、ソリューションは機能しませんでした(ただし、十分なインスピレーションを与えてくれました。ありがとうございます!!)

private void browserIntegration(string defaultPdfProgram)
    {
        try
        {
            RegistryKey reader = null;
            string[] vers = null;

            #region Walters Versuch
            reader = Registry.CurrentUser.OpenSubKey("Software").OpenSubKey("Adobe");
            reader = reader.OpenSubKey("Acrobat Reader");
            vers = reader.GetSubKeyNames();
            if (vers.Contains<string>("9.0"))
            {
                reader = reader.OpenSubKey("9.0");
                reader = reader.OpenSubKey("Originals", true);
                if (reader.GetValueNames().Contains<string>("bBrowserIntegration"))
                    reader.SetValue("bBrowserIntegration", 1, RegistryValueKind.DWord);
                // wenn der Key fehlt ist Browserintegration auch angeschaltet
                // alternativ: reader.DeleteSubKey("bBrowserIntegration", false);
            }
            else
                MessageBox.Show(
                    "In case you run into problems later, please make sure yourself to select\n'Show PDF in Browser' in Acrobat Reader's Settings"
                    , "Unknown Version of Acrobat Reader");

            #endregion
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message + "\n" + ex.StackTrace
                + "\nIn case you run into problems later, please make sure yourself to select\n'Show PDF in Browser' in Acrobat Reader's Settings"
                , "Error while switching on 'Browserintegration' in 'Acrobat Reader'");
        }
}
于 2010-04-30T08:59:30.030 に答える
0

どうもありがとう!

AdobeReaderXIでも動作を再現できることを付け加えたいと思います。(Windows XP32ビット-VB.net2005.)

レジストリキーは(*):

HKEY_CURRENT_USER\Software\Adobe\Acrobat Reader\11.0\Originals\bBrowserIntegration

そのキー値が1の場合、ActiveXコンポーネントは正しくインスタンス化されます。そのキー値が0の場合、フォームのインスタンス化で例外が発生します。

AdobeReaderXIインターネットのプロパティページでブラウザ統合オプションが見つかりませんでした。

(*)このページでその値を見つけました:http: //forums.adobe.com/thread/1042774

于 2013-03-27T10:52:31.033 に答える