G
Guest
I recently upgraded multiple machines from Windows 2000 to XP Professional.
The first machine I setup, I installed SP2, then came to find out that when
scanning a barcode, my program could not read and interupt the information.
So, thinking it was an SP2 problem, I setup my other machine with XP
Professional, but kept it at SP1. Same issue when trying to scan. Below I
have listed a copy of my source. If anyone knows where I could get help to
solve this problem, i'd really appreciate it. NOTE: If you do a search for
"BatchScan Read_Barcode Error Reading Barcode. Return Code:" you will find
where my code runs into a problem.
Thanx in advance,
Mike
SOURCE CODE:
Public Function Read_Barcode() As String(
'*************************************************************************************
'*
'*************************************************************************************
On Error GoTo ErrorHandler:
Dim strBarCodes() As String
Dim pixBarCode As PixEzRegion
Dim bminfo As BITMAP
Dim srcBM As Long ' not declared -- two 02/24/00
Dim x As Long ' not declared -- two 02/24/00
Dim dstDC As Long ' not declared -- two 02/24/00
Dim srcDC As Long ' not declared -- two 02/24/00
Dim bmSize As Long ' not declared -- two 02/24/00
Dim bmBits As Long ' not declared -- two 02/24/00
Dim dstBM As Long ' not declared -- two 02/24/00
Dim B As Long ' not declared -- two 02/24/00
Dim A As Long ' not declared -- two 02/24/00
'***C0008-TAR-------------------------------------------------------------10/16/2003***
'***
***
pgmState = ss40_Read_Barcode
'***
**
'***C0008-TAR-------------------------------------------------------------10/16/2003***
'Creates a new Region object on a specified PixEzImage control.
Set pixBarCode = pixScan.RegionCreate
'specifies where to look for barcode (Sets the positions of a region in
pixels)
pixBarCode.Top = 0
pixBarCode.Left = 0
pixBarCode.Width = (8 * pixScan.ScanResolution)
pixBarCode.Height = (5 * pixScan.ScanResolution)
'Copies the selected or specified region’s image to the Windows clipboard
pixBarCode.Copy
OpenClipboard (frmScan.hwnd)
srcBM = GetClipboardData(CF_BITMAP)
x = w32GetObject(srcBM, Len(bminfo), bminfo)
'Get Device Context for copy
dstDC = CreateCompatibleDC(frmScan.hdc)
srcDC = CreateCompatibleDC(frmScan.hdc)
'Allocate memory for the bitmap
bmSize = ((bminfo.bmWidth / 16) + 1) * bminfo.bmHeight
bmBits = GlobalAlloc(GMEM_FIXED, bmSize)
'By creating a bitmap with only 1 bit per pixel the barcode sw can read it
dstBM = CreateBitmap(bminfo.bmWidth, bminfo.bmHeight, 0, 1, bmBits)
'You need to select the bitmap into the device context
B = SelectObject(srcDC, srcBM)
A = SelectObject(dstDC, dstBM)
'Now do the copy
x = BitBlt(dstDC, 0, 0, bminfo.bmWidth, bminfo.bmHeight, srcDC, 0, 0,
SRCCOPY)
'Now the barcode read will work
x = axrBarCode.ReadBarcodeBitmap(dstBM, 200, 200)
'DJP 08/26/2000
If x <> 0 And x <> 48 Then ' If not readOK and not No Barcode
MsgBox ("BatchScan Read_Barcode Error Reading Barcode. Return Code:"
& x)
App.LogEvent Now & " Error Reading Barcode. Return Code:" & x,
vbLogEventTypeError
End If
'this is how many barcodes it found in the "region"
Select Case axrBarCode.ReadOutCount
Case 0
'It is a non-separator sheet, pass a zero to Process_Image
ReDim strBarCodes(1)
strBarCodes(0) = "0"
Case 1
'Only 1 barcode present; It's a document or a subcomponent
separator.
'Really we do the same thing for both, BUT we want to
'validate that it is either one or the other.
ReDim strBarCodes(1)
If axrBarCode.ReadOutString = "DOCSEP" Or _
Left(axrBarCode.ReadOutString, 10) = "SUBCOMPSEP" Then
'it's a document or subcomponent, pass the code
strBarCodes(0) = axrBarCode.ReadOutString
Else
'it's neither
strBarCodes(0) = "0"
End If
Case 2
'Two barcodes present; It's a batch
ReDim strBarCodes(2)
'readoutindex is the index pointing to which barcode when more
than one was found
axrBarCode.ReadOutIndex = 0
'checking 1st barcode's readoutstring
If axrBarCode.ReadOutString = "BATSEP" Then
'passing code...
strBarCodes(0) = axrBarCode.ReadOutString
Else
strBarCodes(0) = "0"
End If
'storing away 2nd barcode's readoutstring
axrBarCode.ReadOutIndex = 1
strBarCodes(1) = axrBarCode.ReadOutString
Case Else
strBarCodes(0) = "0"
End Select
'Cleanup by deleting the DC's
x = SelectObject(srcDC, B)
x = SelectObject(dstDC, A)
DeleteObject (dstBM)
DeleteObject (srcBM)
DeleteDC (srcDC)
DeleteDC (dstDC)
x = CloseClipboard()
'free the memory that contains the bitmap
GlobalFree (bmBits)
Read_Barcode = strBarCodes
Exit Function
ErrorHandler:
ErrorCheck "Batch Scan - Read_Barcode ", Err.Description, Err.Number
End Function
The first machine I setup, I installed SP2, then came to find out that when
scanning a barcode, my program could not read and interupt the information.
So, thinking it was an SP2 problem, I setup my other machine with XP
Professional, but kept it at SP1. Same issue when trying to scan. Below I
have listed a copy of my source. If anyone knows where I could get help to
solve this problem, i'd really appreciate it. NOTE: If you do a search for
"BatchScan Read_Barcode Error Reading Barcode. Return Code:" you will find
where my code runs into a problem.
Thanx in advance,
Mike
SOURCE CODE:
Public Function Read_Barcode() As String(
'*************************************************************************************
'*
'*************************************************************************************
On Error GoTo ErrorHandler:
Dim strBarCodes() As String
Dim pixBarCode As PixEzRegion
Dim bminfo As BITMAP
Dim srcBM As Long ' not declared -- two 02/24/00
Dim x As Long ' not declared -- two 02/24/00
Dim dstDC As Long ' not declared -- two 02/24/00
Dim srcDC As Long ' not declared -- two 02/24/00
Dim bmSize As Long ' not declared -- two 02/24/00
Dim bmBits As Long ' not declared -- two 02/24/00
Dim dstBM As Long ' not declared -- two 02/24/00
Dim B As Long ' not declared -- two 02/24/00
Dim A As Long ' not declared -- two 02/24/00
'***C0008-TAR-------------------------------------------------------------10/16/2003***
'***
***
pgmState = ss40_Read_Barcode
'***
**
'***C0008-TAR-------------------------------------------------------------10/16/2003***
'Creates a new Region object on a specified PixEzImage control.
Set pixBarCode = pixScan.RegionCreate
'specifies where to look for barcode (Sets the positions of a region in
pixels)
pixBarCode.Top = 0
pixBarCode.Left = 0
pixBarCode.Width = (8 * pixScan.ScanResolution)
pixBarCode.Height = (5 * pixScan.ScanResolution)
'Copies the selected or specified region’s image to the Windows clipboard
pixBarCode.Copy
OpenClipboard (frmScan.hwnd)
srcBM = GetClipboardData(CF_BITMAP)
x = w32GetObject(srcBM, Len(bminfo), bminfo)
'Get Device Context for copy
dstDC = CreateCompatibleDC(frmScan.hdc)
srcDC = CreateCompatibleDC(frmScan.hdc)
'Allocate memory for the bitmap
bmSize = ((bminfo.bmWidth / 16) + 1) * bminfo.bmHeight
bmBits = GlobalAlloc(GMEM_FIXED, bmSize)
'By creating a bitmap with only 1 bit per pixel the barcode sw can read it
dstBM = CreateBitmap(bminfo.bmWidth, bminfo.bmHeight, 0, 1, bmBits)
'You need to select the bitmap into the device context
B = SelectObject(srcDC, srcBM)
A = SelectObject(dstDC, dstBM)
'Now do the copy
x = BitBlt(dstDC, 0, 0, bminfo.bmWidth, bminfo.bmHeight, srcDC, 0, 0,
SRCCOPY)
'Now the barcode read will work
x = axrBarCode.ReadBarcodeBitmap(dstBM, 200, 200)
'DJP 08/26/2000
If x <> 0 And x <> 48 Then ' If not readOK and not No Barcode
MsgBox ("BatchScan Read_Barcode Error Reading Barcode. Return Code:"
& x)
App.LogEvent Now & " Error Reading Barcode. Return Code:" & x,
vbLogEventTypeError
End If
'this is how many barcodes it found in the "region"
Select Case axrBarCode.ReadOutCount
Case 0
'It is a non-separator sheet, pass a zero to Process_Image
ReDim strBarCodes(1)
strBarCodes(0) = "0"
Case 1
'Only 1 barcode present; It's a document or a subcomponent
separator.
'Really we do the same thing for both, BUT we want to
'validate that it is either one or the other.
ReDim strBarCodes(1)
If axrBarCode.ReadOutString = "DOCSEP" Or _
Left(axrBarCode.ReadOutString, 10) = "SUBCOMPSEP" Then
'it's a document or subcomponent, pass the code
strBarCodes(0) = axrBarCode.ReadOutString
Else
'it's neither
strBarCodes(0) = "0"
End If
Case 2
'Two barcodes present; It's a batch
ReDim strBarCodes(2)
'readoutindex is the index pointing to which barcode when more
than one was found
axrBarCode.ReadOutIndex = 0
'checking 1st barcode's readoutstring
If axrBarCode.ReadOutString = "BATSEP" Then
'passing code...
strBarCodes(0) = axrBarCode.ReadOutString
Else
strBarCodes(0) = "0"
End If
'storing away 2nd barcode's readoutstring
axrBarCode.ReadOutIndex = 1
strBarCodes(1) = axrBarCode.ReadOutString
Case Else
strBarCodes(0) = "0"
End Select
'Cleanup by deleting the DC's
x = SelectObject(srcDC, B)
x = SelectObject(dstDC, A)
DeleteObject (dstBM)
DeleteObject (srcBM)
DeleteDC (srcDC)
DeleteDC (dstDC)
x = CloseClipboard()
'free the memory that contains the bitmap
GlobalFree (bmBits)
Read_Barcode = strBarCodes
Exit Function
ErrorHandler:
ErrorCheck "Batch Scan - Read_Barcode ", Err.Description, Err.Number
End Function