2012-03-29 55 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