Available in LEADTOOLS Barcode Modules.
|
L_BarCodeGetDuplicated
#include "ltbar.h"
L_LTBAR_API L_INT L_BarCodeGetDuplicated(pBarCodeDataItem)
pBARCODEDATA pBarCodeDataItem; |
/* pointer to a BARCODEDATA structure */ |
Returns the index of the first barcode that is a duplicate of the specified barcode.
Parameter |
Description |
pBarCodeDataItem |
Pointer to the BARCODEDATA structure that contains barcode information. |
Returns
>= 0 |
The index of the duplicated barcode. |
< 0 |
An error occurred. Refer to Return Codes. |
Comments
LEADTOOLS provides a number of functions to let you work with duplicated barcodes. They let you:
Find the number of duplicates of a specific barcode
Determine whether a specific barcode is duplicated
Get the index of the first duplicated barcode
Get the index of a subsequent barcode
To determine whether a barcode is duplicated, use the L_BarCodeIsDuplicated function. If a barcode is duplicated, L_BarCodeGetDuplicated will return the index of the first barcode in the array after the specified barcode, which is a duplicate of the specified barcode.
If you know the index of a barcode within an array, you can get the index of the first duplicate of the specified barcode using L_BarCodeGetFirstDuplicated. Use the L_BarCodeGetNextDuplicated to get the next instance of a duplicated barcode.
Although no function is included to tell you the number of different sets of barcodes that are duplicated, you can easily program this by using the following code:
L_INT i, j, nCount;
L_BOOL * pbVisited = (L_BOOL *)malloc(pBarCodeData->nTotalCount*sizeof(L_BOOL));
memset(pbVisited, 0, pBarCodeData->nTotalCount*sizeof(L_BOOL));
nCount = 0;
for (i=0; i<pBarCodeData->nTotalCount; i++)
{
if(pbVisited[i])
continue;
pbVisited[i] = TRUE;
nCount++;
j = i;
while(pBarCodeData[j].nIndexDuplicate != -1)
{
j = pBarCodeData[j].nIndexDuplicate;
pbVisited[j] = TRUE;
}
}
free(pbVisited);
After this code is executed, nCount will contain the number of different sets of barcodes.
Required DLLs and Libraries
LTBAR For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application |
Win32, x64, Mobile
See Also
Functions: |
L_BarCodeRead, L_BarCodeFree, L_BarCodeIsDuplicated, L_BarCodeGetNextDuplicated, L_BarCodeVersionInfo, L_BarCodeGetFirstDuplicated, L_BarCodeWrite |
Topics: |
Example
For complete sample code refer to MFCBar32 demo.
L_INT BarCodeGetDuplicatedExample(HWND hWnd, pBARCODEDATA pBarCodeData) { L_INT nDupIndex=0; L_TCHAR szBuffer[256]; if (!pBarCodeData) return FAILURE; ZeroMemory(szBuffer, sizeof(szBuffer)); if (L_BarCodeIsDuplicated(&(pBarCodeData)[0])) { nDupIndex = L_BarCodeGetDuplicated(&(pBarCodeData)[0]); if (nDupIndex >= 0) { // Print the first duplicated barcode data wsprintf(szBuffer, TEXT("Data is %hs\nType %d\nUnits %d\nPosX %d\nPosY %d\nWidth %d\nHeight %d\n\n"), (pBarCodeData)[nDupIndex].pszBarCodeData, (pBarCodeData)[nDupIndex].ulType, (pBarCodeData)[nDupIndex].nUnits, (pBarCodeData)[nDupIndex].rcBarLocation.left, (pBarCodeData)[nDupIndex].rcBarLocation.top, abs((pBarCodeData)[nDupIndex].rcBarLocation.right - (pBarCodeData)[nDupIndex].rcBarLocation.left), abs((pBarCodeData)[nDupIndex].rcBarLocation.bottom - (pBarCodeData)[nDupIndex].rcBarLocation.top)); MessageBox(hWnd, szBuffer, TEXT("BarCode Info."), MB_OK); // find the next (second) duplicated barcode data nDupIndex = L_BarCodeGetNextDuplicated(pBarCodeData, nDupIndex); if (nDupIndex >= 0) { wsprintf(szBuffer, TEXT("Data is %hs\nType %d\nUnits %d\nPosX %d\nPosY %d\nWidth %d\nHeight %d\n\n"), (pBarCodeData)[nDupIndex].pszBarCodeData, (pBarCodeData)[nDupIndex].ulType, (pBarCodeData)[nDupIndex].nUnits, (pBarCodeData)[nDupIndex].rcBarLocation.left, (pBarCodeData)[nDupIndex].rcBarLocation.top, abs((pBarCodeData)[nDupIndex].rcBarLocation.right - (pBarCodeData)[nDupIndex].rcBarLocation.left), abs((pBarCodeData)[nDupIndex].rcBarLocation.bottom - (pBarCodeData)[nDupIndex].rcBarLocation.top)); MessageBox(hWnd, szBuffer, TEXT("BarCode Info."), MB_OK); return SUCCESS; } } if (nDupIndex < 0) { wsprintf(szBuffer, TEXT("An error occurred \nError Code = %d\n"), nDupIndex); MessageBox(hWnd, szBuffer, TEXT("Notice!"), MB_OK); return nDupIndex; } } else { wsprintf(szBuffer, TEXT("This Barcode is not duplicated ...")); MessageBox(hWnd, szBuffer, TEXT("Notice!"), MB_OK); } return SUCCESS; }