FaxComExLib问题

时间:2011-09-26 11:56:30

标签: c# fax

我可以使用FAXCOMLib成功传真信息。现在我尝试使用FAXCOMEXLib,但我遇到了问题:/

这是代码(来自MSDN VB示例):

    try
    {
        FaxServer objFaxServer = new FaxServer();
        FaxDocument objFaxDocument = new FaxDocument();
        object JobID;

        objFaxServer.Connect(Environment.MachineName);
        objFaxDocument.Body = "test.bmp";
        objFaxDocument.DocumentName = "Test name";
        objFaxDocument.Recipients.Add("xxxxxxx", "Name");

        objFaxDocument.AttachFaxToReceipt = true;

        objFaxDocument.CoverPageType = FAXCOMEXLib.FAX_COVERPAGE_TYPE_ENUM.fcptSERVER;
        objFaxDocument.CoverPage = "generic";
        objFaxDocument.Note = "Here is the info you requested";
        objFaxDocument.ReceiptAddress = "someone@example.com";
        objFaxDocument.ReceiptType = FAXCOMEXLib.FAX_RECEIPT_TYPE_ENUM.frtMAIL;
        objFaxDocument.ScheduleType = FAXCOMEXLib.FAX_SCHEDULE_TYPE_ENUM.fstNOW;
        objFaxDocument.Subject = "Today's fax";

        objFaxDocument.Sender.Title = "Mr.";
        objFaxDocument.Sender.Name = "Bob";
        objFaxDocument.Sender.City = "Cleveland Heights";
        objFaxDocument.Sender.State = "Ohio";
        objFaxDocument.Sender.Company = "Microsoft";
        objFaxDocument.Sender.Country = "USA";
        objFaxDocument.Sender.Email = "someone@microsoft.com";
        objFaxDocument.Sender.FaxNumber = "12165555554";
        objFaxDocument.Sender.HomePhone = "12165555555";
        objFaxDocument.Sender.OfficeLocation = "Downtown";
        objFaxDocument.Sender.OfficePhone = "12165555553";
        objFaxDocument.Sender.StreetAddress = "123 Main Street";
        objFaxDocument.Sender.TSID = "Office fax machine";
        objFaxDocument.Sender.ZipCode = "44118";
        objFaxDocument.Sender.BillingCode = "23A54";
        objFaxDocument.Sender.Department = "Accts Payable";

        JobID = objFaxDocument.ConnectedSubmit(objFaxServer);

        MessageBox.Show(("The Job ID is :" + JobID.ToString()),"Finished");

        objFaxServer.Disconnect();

    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message.ToString() + ". " + ex.ToString(), "Exception");
    }

该行引发异常:FaxServer objFaxServer = new FaxServer();

  

无法将“System .__ ComObject”类型的COM对象强制转换为接口类型“FAXCOMEXLib.FaxServer”。

当我这样做时: FaxServer objFaxServer = new FaxServerClass(); 我甚至无法编译该行..它显示: Interop type 'FAXCOMEXLib.FaxServerClass' cannot be embedded. Use the applicable interface instead.

所以,我在那条线上停了下来:/

顺便说一句。基本上,我想实现一个发送传真并观察已发送消息状态的类。如果有人发送一个完整的准备使用课程,我会非常高兴。

请帮助我,

2 个答案:

答案 0 :(得分:3)

  

当我这样做时:FaxServer objFaxServer = new FaxServerClass();我甚至不能   编译该行

关于COM对象的奇怪之处在于接口有时就像它们具有构造函数一样:

FaxServer objFaxServer = new FaxServer();

这是正确的路线。我有它在我的,它的工作原理。互操作可能有问题。

答案 1 :(得分:1)

执行以下步骤来克服此问题:

  1. 在解决方案资源管理器中从引用中选择FAXCOMEXLib。
  2. 打开属性
  3. 设置"启用互操作类型"为假。