The purpose of this tutorial is to provide you with a quick and easy way to generate a Barcode program. Perform the following steps to create and run a program that reads barcodes.
Create a new directory in the \Examples\CDLL directory called BarcodeTutor.
Copy everything in the SimpleLoad directory into the BarcodeTutor directory.
Compile the project as it is and run SimpleLoad.exe to familiarize yourself with the basic program.
In the Imports.cpp file, add the following lines:
#if defined(WIN64)
#pragma comment(lib, "..\\..\\..\\Lib"L_VER_DESIGNATOR"\\CDLL\\x64\\Ltbar_x.lib")
#else
#pragma comment(lib, "..\\..\\..\\Lib"L_VER_DESIGNATOR"\\CDLL\\Win32\\Ltbar_u.lib")
#endif // #if defined(WIN64)
Add the following line in StdAfx.h in the BarcodeTutor directory:
#include "..\..\..\include\ltbar.h"
Define the following global variables in Ezfunc.h in the BarcodeTutor directory:
pBARCODEDATA pBarCodes;
#define IDM_READ_BARCODES 200
Add the following statements in the WinMain function as follows:
Add the following before calling InitInstance() statement:
if (L_BarCodeInit(BARCODES_1D) != SUCCESS)
return 0;
pBarCodes = NULL;
Add the following after the GetMessage() loop:
if (pBarCodes)
L_BarCodeFree(&pBarCodes);
L_BarCodeExit();
Edit EZFUNC.RC file in the BarcodeTutor directory and add the following lines:
#include "EZFUNC.H"
MAIN_MENU MENU
BEGIN
MENUITEM "Read Barcodes" IDM_READ_BARCODES
END
In InitApplication, change the line:
wcWindowClass.lpszMenuName = NULL;
wcWindowClass.lpszMenuName = TEXT("MAIN_MENU");
In MainWndProc, change the line:
Demos_CombinePath(szImagesDirectory, L_TEXT("Image1.cmp"), szFilename, _countof(szFilename));
To:
Demos_CombinePath(szImagesDirectory, L_TEXT("barcode1.tif"), szFilename, _countof(szFilename));
In InitInstance, change the menu parameter in CreateWindow from NULL to LoadMenu(hInstance, MAKEINTRESOURCE("MAIN_MENU"))
In the MainWndProc procedure, add the following code to the switch statement:
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDM_READ_BARCODES:
{
BARCODE1D Bar1d;
memset(&Bar1d, 0, sizeof(BARCODE1D));
Bar1d.uStructSize = sizeof(BARCODE1D);
Bar1d.bErrorCheck = TRUE;
Bar1d.nGranularity = 9;
Bar1d.nDirection = BARCODE_DIR_HORIZONTAL;
BARCODECOLOR BarColor;
memset(&BarColor, 0, sizeof(BARCODECOLOR));
BarColor.uStructSize = sizeof(BARCODECOLOR);
BarColor.dwColorBar = RGB(0, 0, 0);
BarColor.dwColorSpace = RGB(255, 255, 255);
// The Read method will search for all linear barcodes in the whole bitmap
L_INT nRet = L_BarCodeRead(&LeadBitmap,
NULL,
BARCODE_1D_READ_ANYTYPE,
BARCODE_SCANLINES_PER_PIXELS,
BARCODE_BLOCK_SEARCH,
0, &Bar1d, NULL, &BarColor,
&pBarCodes, sizeof(BARCODEDATA));
if (nRet == SUCCESS)
{
L_INT nCount = pBarCodes->nTotalCount;
L_CHAR szBuffer[MAX_PATH];
for (L_INT i = 0; i<ncount; i++)
{
memset(szbuffer, 0, max_path);
wsprintfa(szbuffer,
"Barcode # %d\nData %s\nLeft %d\nTop %d\nRight %d\nBottom %d\n",
i,
pbarcodes[i].pszbarcodedata,
pbarcodes[i].rcbarlocation.left,
pbarcodes[i].rcbarlocation.top,
pbarcodes[i].rcbarlocation.right,
pbarcodes[i].rcbarlocation.bottom);
messageboxa(hwnd, szbuffer, ("barcode data"), mb_ok);
}
}
else
messagebox(hwnd, text("failure during reading linear barcodes"), text("error!"), mb_ok);
}
break;
}
return 0;
On the Build menu, select Build SimpleLoad.exe.
On the Build menu, select Execute SimpleLoad.exe.
Save this project to use for testing other code samples.