我需要让用户从自定义列表框中选择扫描仪。 选择扫描仪后,用户可以选择一个按钮开始扫描过程。
当我使用自己的方法执行此操作SetDataSource
时,我收到“访问冲突”
public bool SetDataSource(string id)
{
//check first scanner
TwRc rc = DSMident(_appid, IntPtr.Zero, TwDg.Control, TwDat.Identity, TwMsg.GetFirst, _srcds);
if (_srcds.Id.ToString() == id)
{
return true;
}
rc = TwRc.Success;
//check other scanners
while (rc == TwRc.Success)
{
rc = DSMident(_appid, IntPtr.Zero, TwDg.Control, TwDat.Identity, TwMsg.GetNext, _srcds);
if (_srcds.Id.ToString() == id)
{
return true;
}
}
return false;
}
public void Acquire()
{
TwRC rc;
CloseSrc();
if (appid.Id == IntPtr.Zero)
{
Init(hwnd);
if (appid.Id == IntPtr.Zero)
return;
}
rc = DSMident(appid, IntPtr.Zero, TwDG.Control, TwDAT.Identity, TwMSG.OpenDS, srcds);
if (rc != TwRC.Success)
return;
TwCapability cap = new TwCapability(TwCap.XferCount, 1);
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, cap);
if (rc != TwRC.Success)
{
CloseSrc();
return;
}
TwUserInterface guif = new TwUserInterface();
guif.ShowUI = 0;
guif.ModalUI = 0;
guif.ParentHand = hwnd;
rc = DSuserif(appid, srcds, TwDG.Control, TwDAT.UserInterface, TwMSG.EnableDS, guif);
if (rc != TwRC.Success)
{
CloseSrc();
return;
}
}
选择数据源(扫描仪)的常用方法是调用它:
rc = DSMident(_appid, IntPtr.Zero, TwDg.Control, TwDat.Identity, TwMsg.UserSelect, _srcds);
我测试了这段代码并且它有效。但是在执行此操作时,会出现带有列表框的对话框。我希望自己的列表框没有AccessViolationException
。我怎样才能做到这一点?
此处的文档http://www.twain.org/wp-content/uploads/2016/03/TWAIN-2.1-Spec.pdf 说我应该保存我的数据源并在获取中打开它(第111页)
乱码的代码可以在这里找到: https://www.codeproject.com/Articles/1376/NET-TWAIN-image-scanner