Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top