我使用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