Does anyone have experience using EZTwain's BARCODE_Recognize function?
I'm wondering why I'm getting an AccessViolationException
in my program when trying to use the Dosadi EZTwain library to recognize bar codes from scanned images.
This program runs flawlessly on our dev environment, so I'm having a hard time tracking down what exactly is the cause of the problem when it runs on the client's PCs.
I've found through using the ildasm.exe program that the exception originates in this method of my barcode recognition utility class.
Edit: I'm wondering if it could have anything to do with our users not being set up as administrators? Since we have no problems at all running it here as admin, then they get this exception the first time it calls this GetBarcode method?
Edit: Is there anything else anyone else would need to see from my code to help me track down this problem?
The ildasm where the error occurs looks like this. The error is on IL_00bb: ldloc.3 which is the first parameter "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;
}