我使用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.
任何人都可以建议我什么这里的问题是 感谢
你能告诉我们在哪一行抛出异常吗?附上一个调试器,它会帮助你。我想它必须抛出我的Ctor of Scanner类或Scann()方法。也许通过没有帮助? – Zenwalker 2012-03-29 10:22:33
@zenwalker,我编辑它。你认为这可能是因为该DLL没有正确注册。 – freebird 2012-03-29 10:24:38
当你甚至没有连接扫描仪时,你是否认真提问? – 2012-03-29 15:05:38