L_BarCodeGetDuplicated

Summary

Returns the index of the first barcode that is a duplicate of the specified barcode.

Syntax

#include "ltbar.h"

L_LTBAR_API L_INT L_BarCodeGetDuplicated(pBarCodeDataItem)

Parameters

pBARCODEDATA pBarCodeDataItem

Pointer to the BARCODEDATA structure that contains barcode information.

Returns

Value Meaning
>= 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:

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

Platforms

Win32, x64, Linux.

See Also

Functions

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; 
} 

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Barcode C API Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.