有没有人有使用EZTwain的BARCODE_Recognize函数的经验?在客户端PC上获取AccessViolationException
我想知道为什么我在使用Dosadi EZTwain库识别扫描图像中的条形码时在我的程序中得到AccessViolationException
。
这个程序在我们的开发环境中完美运行,所以我很难追查在客户端PC上运行时问题的原因究竟是什么。
我发现通过使用ildasm.exe程序,异常源于我的条形码识别实用程序类的这种方法。
编辑:我想知道它是否可以与我们的用户没有设置为管理员有什么关系?由于我们没有任何问题,所以在这里以管理员身份运行它,那么他们在第一次调用此GetBarcode方法时会得到此异常?
编辑:还有其他人需要从我的代码中看到,以帮助我追踪这个问题吗?
发生错误的ildasm看起来像这样。该错误在IL_00bb:ldloc.3上,这是第一个参数“image”。
//000053: count = EZTwain.BARCODE_Recognize(image, -1, -1);
IL_00bb: ldloc.3
IL_00bc: ldc.i4.m1
IL_00bd: ldc.i4.m1
IL_00be: call int32 Dosadi.EZTwain.EZTwain/*02000005*/::BARCODE_Recognize(native int,
int32,
int32) /* 060001E4 */
IL_00c3: stloc.1
GetBarcode
public static string GetBarcode(Bitmap bImage, out BarcodeType barcodeType)
{
barcodeType = BarcodeType.NotBarcode;
string selectedBarcode = null;
int count = 0;
IntPtr hImage = IntPtr.Zero, image = IntPtr.Zero;
List<string> barcodes = new List<string>();
try
{
try
{
if (bImage.Width == 0 || bImage.Height == 0)
{
return null;
}
hImage = bImage.GetHbitmap();
if (hImage == IntPtr.Zero)
{
return null;
}
image = EZTwain.DIB_FromBitmap(hImage, IntPtr.Zero);
}
catch (Exception ex)
{
logger.LogException(LogLevel.Debug,
"Exception in GetBarcode(): inner try-catch block", ex);
throw;
}
finally
{
if (hImage != IntPtr.Zero)
DeleteObject(hImage);
}
EZTwain.BARCODE_SetDirectionFlags(-1);
count = EZTwain.BARCODE_Recognize(image, -1, -1);
UtilDebug("Found {0} barcodes in image on first attempt.", count);
for (int i = 0; i < count; i++)
{
barcodes.Add(EZTwain.BARCODE_Text(i));
}
foreach (string code in barcodes)
{
UtilDebug("Processing barcode \"{0}\".", code);
if (ProcessBarcodeType(code) == BarcodeType.CoversheetBarcode || ProcessBarcodeType(code) == BarcodeType.RegularBarcode)
{
barcodeType = ProcessBarcodeType(code);
selectedBarcode = code;
UtilDebug("SelectedBarcode set to \"{0}\".", code);
break;
}
}
}
catch (Exception ex)
{
logger.LogException(LogLevel.Debug, "Exception in GetBarcode(): outer try-catch block", ex);
throw;
}
finally
{
if (image != IntPtr.Zero)
EZTwain.DIB_Free(image);
barcodes.Clear();
}
//Find one that is an ASI barcode before return
return selectedBarcode;
}
我想我已经解决了我们在其他评论中创建HDIB的方式,但是我只是想说感谢在尝试帮助我解决我的问题之后。它确实让我想我应该看看我们是否可以从eztwain.com升级到3.43版本,但是我仍然不知道它是否与我们在3.30版本上构建的产品兼容,我们将不得不安装这个我认为所有客户机器上都有新版本。 – Zack
我不确定是否有办法在SO上发送消息,但我突然再次遇到同样的问题,并且现在有一个Dosadi日志以及关于新错误的更多信息http://stackoverflow.com/questions/25895706/client-pc-suddenly-getting-accessviolationexception-using-eztwain – Zack