2011-09-26 47 views
1

我可以使用FAXCOMLib成功傳真信息。現在,我嘗試使用FAXCOMEXLib,但我有這樣的問題:/問題與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 = "[email protected]"; 
     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 = "[email protected]"; 
     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 =新FaxServer ();

無法將'System .__ ComObject'類型的COM對象轉換爲接口類型'FAXCOMEXLib.FaxServer'。

當我這樣做:FaxServer objFaxServer = new FaxServerClass(); 我甚至無法編譯線。它表明:Interop type 'FAXCOMEXLib.FaxServerClass' cannot be embedded. Use the applicable interface instead.

所以,我停在該行:/

BTW。基本上,我想實現一個將發送傳真並觀察發送消息狀態的類。我會非常高興的是,如果有人發送整個準備好使用類。

請幫助我,

回答

3

當我這樣做:FaxServer objFaxServer =新FaxServerClass();我甚至不能 編譯線

奇怪的事情有關COM對象是接口有時表現爲雖然他們具有構造:

FaxServer objFaxServer = new FaxServer(); 

這是正確的路線。我有我的,它的工作原理。互操作可能有問題。

+0

謝謝!這非常有幫助! – Flea

1

執行下列步驟來解決這個問題:

  1. 選擇FAXCOMEXLib在解決方案資源管理refrences。
  2. 打開屬性
  3. 將「啓用Interop類型」設置爲False。