开发者

Problem with FaxComExLib

I can successfully fax messages using FAXCOMLib. Now I try to use FAXCOMEXLib, but I have problems with that:/

This is the code (from MSDN VB example):

    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");
    }

The exception is thrown on that line: FaxServer objFaxServer = new FaxServer();

Unable to cast COM object of type 'System.__ComObject' to interface type 'FAXCOMEXLib.FaxServer'.

When I do: FaxServer objFaxServer = new FaxServerClass(); I can't even compile that line.. It shows: Interop type 'FAXCOMEXLib.FaxServerClass' cannot be embedded. Use the applicable interface instead.

So, I was stopped on that line :/

BTW. Basically, I want to implement a class开发者_StackOverflow社区 that will send faxes and watch the status of sent messages. I would be very very pleased, if somebody send a whole ready to use class.

Please help me,


When I do: FaxServer objFaxServer = new FaxServerClass(); I can't even compile that line

Weird thing about COM objects is that interfaces sometimes act as though they have constructors:

FaxServer objFaxServer = new FaxServer();

That is the correct line. I have it on mine and it works. There may be something wrong with the interop.


Do the following steps to overcome this issue:

  1. Select FAXCOMEXLib from refrences in Solution Explorer.
  2. Open Properties
  3. Set "Enable Interop Type" to False.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜