当我尝试在 C# 中实例化这样的 PDF 浏览器控件时:
AcroPDFLib.AcroPDFClass acrobat = new AcroPDFLib.AcroPDFClass();
我收到带有以下消息的 COMException
:
由于以下错误,从 IClassFactory 创建 CLSID {CA8A9780-280D-11CF-A24D-444553540000} 的 COM 组件实例失败:80004005。
我引用了 AcroPDF.dll组件名称Adobe Acrobat 7.0 浏览器控件类型库 1.0。
当我以管理员身份运行 Visual C# 2008 Express Edition 时,我收到另一条错误消息:
无法将类型“AcroPDFLib.AcroPDFClass”的 COM 对象转换为接口类型“AcroPDFLib.IAcroAXDocShim”。此操作失败,因为对 IID 为“{3B813CE7-7C10-4F84-AD06-9DF76D97A9AA}”的接口的 COM 组件上的 QueryInterface 调用因以下错误而失败:不支持此类接口(HRESULT 异常:0x80004002 (E_NOINTERFACE)) .
当我尝试使用该对象时,这种情况发生在下一行:
acrobat.LoadFile("book.pdf");
我无法弄清楚出了什么问题。帮助最感激!
When I try to instantiate a PDF browser control like this in C#:
AcroPDFLib.AcroPDFClass acrobat = new AcroPDFLib.AcroPDFClass();
I get a COMException
with this message:
Creating an instance of the COM component with CLSID {CA8A9780-280D-11CF-A24D-444553540000} from the IClassFactory failed due to the following error: 80004005.
I have made a reference to AcroPDF.dll which has the component name Adobe Acrobat 7.0 Browser Control Type Library 1.0.
When I run Visual C# 2008 Express Edition as administrator I get another error message:
Unable to cast COM object of type 'AcroPDFLib.AcroPDFClass' to interface type 'AcroPDFLib.IAcroAXDocShim'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{3B813CE7-7C10-4F84-AD06-9DF76D97A9AA}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
This happens at the next line when I try to use the object:
acrobat.LoadFile("book.pdf");
I can't figure out what is wrong. Help most appreciated!
发布评论
评论(2)
.net COM 互操作不会将所有 COM 消息直接路由回调用者。如果您从 STA 调用 COM,它不会理解您的应用程序如何处理重新进入。这意味着只能通过重试来处理的失败消息最终会导致异常。
尝试实现 IMessageFilter 接口。这将使 COM 能够了解如何将消息传递回您的应用程序。特别是,实施 RetryRejectedCall 并检查是否有失败标记,并且可能返回一个超时值(类似于 1000 毫秒)以允许 COM 在短暂暂停后重试。
它是 COM 类型,因此这是定义接口所需的代码:
这是如何实现它的示例:
实现消息过滤器后,您需要使用 CoRegisterMessageFilter。这是按线程注册,因此请注意您在哪个线程上调用它。 PInvoke 签名是:
即使这不起作用,在最至少,如果您在过滤器中记录所有消息,您应该有望获得有关出现问题的更多信息。查看传递到消息过滤器的参数值。如果您查找它们,它们将与错误/状态代码相关。
[请注意,我在这里指的 IMessageFilter 与 System.Windows.Forms.IMessageFilter,因此请确保您不会意外使用 winforms。]
.net COM interop doesn't route all COM messages directly back to the caller. If you called COM from an STA, it won't understand how you app can handle re-entrance. This means that failure messages that could just be handled with a retry, end up causing exceptions.
Try implementing IMessageFilter interface. This will allow COM to understand how to pass messages back to your app. In particular, implement the RetryRejectedCall and check if the failure flags and possibly return a timeout value (something like 1000ms) to allow COM to retry after a brief pause.
It's a COM type, so this is the code you'll need to define the interface:
And this is an example of how you would implement it:
Once you've implemented a message filter you will need to register it using CoRegisterMessageFilter. This is a per-thread registration, so be aware of what thread you are calling it on. The PInvoke signiture is:
Even if this doesn't work, at the very least, if you log all the messages in the filter you should hopefully get some more information about what is going wrong. Look at the values of the parameters being passed into the message filter. If you look them up they will relate to error/state codes.
[Be aware, the IMessageFilter I'm referring to here is different from the System.Windows.Forms.IMessageFilter, so make sure you don't accidentally use the winforms one.]
以下是使用 Adobe PDF Reader 控件的步骤:
我不知道为什么,但我必须以管理权限运行 Microsoft Visual C# 2008 Express Edition 才能使其正常工作。对于有限的用户,我在设计器中收到以下消息:
请注意,将 Adobe PDF Reader 控件添加到工具箱后,已创建一个名为 AxInterop.AcroPDFLib.dll 的新 .NET 互操作程序集。对此新程序集的引用已添加到您的项目引用中。
Adobe PDF Reader 控件的 API 参考文档位于此处: http://icio.us/ajukkr
此论坛thread 提供了一些更有用的信息:http://forums.adobe.com/thread/438362
These are the steps to use the Adobe PDF Reader control:
I'm not sure why but I have to run Microsoft Visual C# 2008 Express Edition with administrative privileges to get this working. With a limited user I get this message in the designer:
Note that after adding the Adobe PDF Reader control to your toolbox a new .NET interop assembly has been created with the name AxInterop.AcroPDFLib.dll. A reference to this new assembly has been added to your project references.
API reference documentation for the Adobe PDF Reader control is located here: http://icio.us/ajukkr
This forum thread provides some more useful information: http://forums.adobe.com/thread/438362