使用 RFCOMAPIlib (RightFax COM API):无法转换 COM 对象

发布于 2024-11-30 12:15:33 字数 700 浏览 0 评论 0原文

我正在使用 RightFax COM API。我想做的只是发送带有附件的传真。简单吧?这个问题已经回答过几次了。但是,当我在应用程序中使用其中一些代码时,我遇到了一些麻烦。

应用程序:RightFax 9.4
语言:C#(ASP.NET 应用程序)
IDE:MS Visual Web 开发。快递
目标框架:.NET 3.5
操作系统:Windows 7

using ...
public static void SendFax(<arguments>)
{
    RFCOMPAPILib.FaxServerClass fs = new RFCOMAPILib.FaxServerClass();
    fs.Name = "faxSvrName";
    // BOOM, exception
}

我什至不知道服务器的名称。

异常详细信息:
无法将类型“RFCOMAPILib.FaxServerClass”的 COM 对象转换为接口类型“RFCOMAPILib.Form”。此操作失败,因为对 IID 为“{9F386618-764B-48F8-A5BF-3682B03DE840}”的接口的 COM 组件上的 QueryInterface 调用由于以下错误而失败:不支持此类接口(HRESULT 异常:0x80004002 (E_NOINTERFACE)) .

那么。有什么建议吗?

I'm working with the RightFax COM API. What I want to do is simply send a fax with an attachment. Simple right? That question has been answered a few times. However, when I use some of that code in my application, I have a little trouble.

Application: RightFax 9.4
Language: C# (ASP.NET Application)
IDE: MS Visual Web Dev. Express
Target Framework: .NET 3.5
OS: Windows 7

using ...
public static void SendFax(<arguments>)
{
    RFCOMPAPILib.FaxServerClass fs = new RFCOMAPILib.FaxServerClass();
    fs.Name = "faxSvrName";
    // BOOM, exception
}

I don't even get past the server's name.

Exception details:
Unable to cast COM object of type 'RFCOMAPILib.FaxServerClass' to interface type 'RFCOMAPILib.Form'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{9F386618-764B-48F8-A5BF-3682B03DE840}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

So. Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光与爱终年不遇 2024-12-07 12:15:33

这个 COM 接口设计得有点过度,但这种模式并不罕见。一个 COM 组件类可以实现多个接口,其中之一是默认接口。 .NET 中不存在该机制,它不支持多重继承或默认接口的概念。 Tlbimp 合成一个名为 mumbleClass 的假包装类来包装名为 mumble 的组件类。这是所有接口实现的所有方法的包。异常消息告诉您的是 FaxServer coclass 的默认接口名为“Form”。并且 RFCOMAPILib.Form 无法转换为 RFCOMAPILib.FaxServerClass。没什么大惊喜。

您需要将代码重写为类似以下内容:

 RFCOMPAPILib.FaxServer fs = new RFCOMAPILib.FaxServerClass();
 fs.Name = "faxSvrName";

我完全猜测接口名称,“IFaxServer”的一些可能性。使用对象浏览器查找实际名称。

This COM interface was over-designed a bit but the pattern is not unusual. A COM coclass can implement multiple interfaces, one of which is the default interface. That mechanism doesn't exist in .NET, it doesn't support multiple inheritance or the notion of a default interface. Tlbimp synthesizes a fake wrapper class with the name mumbleClass to wrap a coclass named mumble. Which is a bag of all the methods implemented by all the interfaces. What the exception message is telling you is that the default interface for the FaxServer coclass is named "Form". And that RFCOMAPILib.Form cannot be cast to RFCOMAPILib.FaxServerClass. No great surprise.

You need to rewrite the code to something resembling this:

 RFCOMPAPILib.FaxServer fs = new RFCOMAPILib.FaxServerClass();
 fs.Name = "faxSvrName";

I'm completely guessing at the interface name, some odds for "IFaxServer". Use Object Browser to find the actual name.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文