15,179,257 members
Articles / Desktop Programming / MFC
Article
Posted 4 Mar 2006

81.3K views
3.4K downloads
39 bookmarked

# EAN-13 BarCode ActiveX Control Drawer

Rate me:
4.70/5 (8 votes)
25 Jun 2007CPOL2 min read
An activeX control that draws any EAN-13 barcode

## Introduction

EAN-13, based upon the UPC-A standard, was implemented by the International Article Numbering Association (EAN) in Europe. This standard was implemented mostly because the UPC-A standard was not well-designed for international use. It was probably also implemented partly because no-one likes the U.S. to be in charge of anything, especially the Europeans.

## Purpose of making it an ActiveX control

There was the need for some code to draw the EAN-13 barcode for an Oracle application. The solution came to be an ActiveX control that may be used anywhere it is registered on a computer, from any language and any environment.

## EAN-13 code structure

A typical EAN-13 barcode looks something like this:

## Check the code for validity by the parity code, the 13th number

C++
```bool CEANBarCode::CheckCode()
{
int Sum = 0;
for(int i=2;i<=12;i+=2)
Sum += GetAt(i) * 3;
for(int i=1;i<=12;i+=2)
Sum += GetAt(i);
if(10-(Sum%10)==GetAt(13))
return true;
return false;
}```

## Then how are the numbers of the code being drawn?

Any number is being represented by a constant binary representation that is translated into white bar for 1 and black bar for 0. This constant is used as-is for the left part when the parity is odd, as a complement for the right part, and as reverse-order for the complement of the left part for even parity code.

## Then EAN-13 is very simple

Thanks to the great reference, Barcode Island, which made me understand it very easily and contain more details about EAN-13.

## Registering the OCX

You can register the OCX by running the following command:

C++
`regsvr32 "c:\BarCode.ocx"`

Replace the path with the original path of the OCX.

## UnRegistering the OCX

Simply by writing the previous line, but with the parameter /u as follows:

C++
`regsvr32 /u "c:\BarCode.ocx"`

## About regsvr32

The Windows tool for registering any self-registered objects such as COM objects. For more information, run the command:

C++
`regsvr32`

## History

• 4 March, 2006 -- Original version posted
• 10 March, 2006 -- Updated
• 25 June, 2007 -- Article edited and moved to the main CodeProject.com article base

## License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

## About the Author

 Web Developer Egypt
C# C++
GDI
MFC
ASP.NET

## Comments and Discussions

 First Prev Next
 EAN-13 BarCode and access Member 1226778616-Jan-16 4:33 Member 12267786 16-Jan-16 4:33
 How should I use this control? MCGRADYV516-Jul-13 23:19 MCGRADYV5 16-Jul-13 23:19
 I should use it just like any other controls in MFC? Could you please show me an example of how to using it in a project.
 Nice Control Ashutosh Phoujdar3-Jun-08 4:08 Ashutosh Phoujdar 3-Jun-08 4:08
 Error in code KL Chin8-Mar-06 19:48 KL Chin 8-Mar-06 19:48
 Re: Error in code Ahmad_Hashem10-Mar-06 5:28 Ahmad_Hashem 10-Mar-06 5:28
 Last Visit: 31-Dec-99 19:00     Last Update: 27-Jan-22 9:35 Refresh 1

General    News    Suggestion    Question    Bug    Answer    Joke    Praise    Rant    Admin

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.