2012-03-29 117 views
-1

我使用c#建立一個小型試驗項目,該項目將掃描圖像。這裏是我的代碼做收到COMException了未處理

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Windows.Forms; 
using WIA; 
namespace Scanner 
{ 
    public class Scanner 
    { 
     Device oDevice; 
     Item oItem; 
     CommonDialogClass dlg; 
     public Scanner() 
     { 

       dlg = new CommonDialogClass(); 
       oDevice = dlg.ShowSelectDevice(WiaDeviceType.UnspecifiedDeviceType, true, false); 


     } 
     public void Scann() 
     { 
      dlg.ShowAcquisitionWizard(oDevice); 
     } 
     /// <summary> 
     /// The main entry point for the application. 
     /// </summary> 
     // [STAThread] 
     static void Main() 
     { 
      Application.EnableVisualStyles(); 
      Application.SetCompatibleTextRenderingDefault(false); 
      Application.Run(new Form1()); 
     } 
    } 
} 

private void button1_Click(object sender, EventArgs e) 
     { 
      Scanner oScanner = new Scanner(); 
      oScanner.Scann(); 
      button1.Text = "Image scanned"; 
      OpenFileDialog dlg = new OpenFileDialog(); 
      if (dlg.ShowDialog() == DialogResult.OK) 
      { 
       pictureBox1.Image = Image.FromFile(dlg.FileName); 
      } 
     } 

但是當我嘗試運行應用程序,然後單擊按鈕,我得到在這條線以下錯誤dlg = new CommonDialogClass();

Creating an instance of the COM component with CLSID {850D1D11-70F3-4BE5-9A11-77AA6B2BB201} from the IClassFactory failed due to the following error: 80070422. 

任何人都可以建議我什麼這裏的問題是 感謝

+0

你能告訴我們在哪一行拋出異常嗎?附上一個調試器,它會幫助你。我想它必須拋出我的Ctor of Scanner類或Scann()方法。也許通過沒有幫助? – Zenwalker 2012-03-29 10:22:33

+0

@zenwalker,我編輯它。你認爲這可能是因爲該DLL沒有正確註冊。 – freebird 2012-03-29 10:24:38

+0

當你甚至沒有連接掃描儀時,你是否認真提問? – 2012-03-29 15:05:38

回答

0

http://mahaafifi.blogspot.co.uk/2012/03/iclassfactory-failed-due-to-following.html

「轉到Windows智優工具=>服務=> WIA服務=>啓用它,並啓動」

希望這有助於。

+0

無法在那裏找到WIA服務。 – freebird 2012-03-29 10:29:50

+0

你認爲這可能是因爲目前我的電腦沒有連接掃描儀。 – freebird 2012-03-29 10:40:50

+0

試試這個:轉到服務管理控制檯(開始 - >運行 - > Services.msc) 確保'Windows Modules Installer'已啓用 然後檢查更新。 – SkonJeet 2012-03-29 10:41:00

相關問題