BarcodeLib – ported to Compact Framework

Print This Post Print This Post

Update 25. ja 2014: see BarcodeLib again ported to CF

I got a request for a barcode image generator for Windows Mobile. Fortunately there are some libs out there including source code and a decided to test to port barcodelib by Brad Barnhill hosted at the famous CodeProject site (http://www.codeproject.com/KB/graphics/BarcodeLibrary.aspx).

How was it done

I downloaded the code, started a new SmartDevice Class Library project in VS2005 and copied the source files into the project dir and started add the existing code files. I did not start with the original project files, as they were created with VS2008 and uses full framework in version 3.5.

After some builds, code changes, adding conditional compiles and one cfhelper class, the class compiled fine for Compact Framework 2. I had to remove (conditional compile options) most of the BarcodeXML stuff, as these are not? portable that easy to CF2.

                            using (Pen pen = new Pen(ForeColor, iBarWidth))
                            {
#if !WindowsCE
                                pen.Alignment = PenAlignment.Right;
#endif
                                while (pos < Encoded_Value.Length)
                                {
                                    if (Encoded_Value[pos] == '1')
#if !WindowsCE
                                        g.DrawLine(pen, new Point(pos * iBarWidth + shiftAdjustment, 0), new Point(pos * iBarWidth + shiftAdjustment, Height));
#else
                                        cfHelper.myDrawLine(g, pen, new Point(pos * iBarWidth + shiftAdjustment, 0), new Point(pos * iBarWidth + shiftAdjustment, Height));
#endif

and here is my helper:

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace BarcodeLib
{
    static class cfHelper
    {
        public static void myDrawLine(Graphics g, Pen p, Point p1, Point p2)
        {
            g.DrawLine(p, p1.X, p1.Y, p2.X, p2.Y);
        }
    }
}

Then I added a BarcodeLibTest smart device Windows Application project using the new BarcodeLib and was able to get barcodes printed on screen and save the images to files.

Download Source: [Download not found]

6 Comments

  1. Is all you changed the DrawLine calls? If so Ill make this change to make it compatible with the Compact Framework.

  2. admin says:

    Yes, I had to change the DrwaLine and PenAlignment code lines AND commented out all XML stuff. That’s all I had to change.

    Great to have ou reading this.

    BTW: to be able to use one source code base, you have to use the #if conditional lines in the code files and create separate project files for smartdevice target. If you have forms in a project, you have to create separate forms for smartdevice projects.

    Regards

    Josef

  3. Wahran says:

    Hi!
    can we encode the fnc3 in the input ?

    regards,
    Riad

  4. josef says:

    @Wahran

    see the original code and read comment http://www.codeproject.com/Articles/20823/Barcode-Image-Generation-Library?msg=3115990#xx3115990xx

    You can encode everything. FNC1 is 102 (hex 86) acording to this site: http://www.adams1.com/128table.html. FNC3 is 96 (hex 80). So simply use “abc”+char(96)+”def” but maintain the standards of barcode encoding.

    ~Josef

  5. teafields says:

    Sorry if this is an idiotic question – how do I get this to run on my windows mobile device? I’ve never compiled a windows mobile app from scratch and wouldn’t know where to start…

    Thanks in advance,
    Thomas

  6. josef says:

    Hello teafields

    you first need the development windows (xp, 7, 8) setup:
    Visual Studio 2008 (no express version)
    Windows Mobile 5 SDK
    Windows Mobile 6.5.3 DTK [optional]
    ActiveSync/Windows Mobile Device Center
    optinal, if you want to use the updated source code: a svn (subversion) or github client, for example TortoiseSVN or TortoiseGit

    Either checkout the updated source using git or svn or use the download provided for the older version suplied here.

    You get a new dir with the source code (either by svn/git or after unpacking the zip download).
    If you want to use the barcodeLib in a new or existing C#/VB.NET SmartDevice project you can add a reference either to the compiled BarcodeLibCF DLL or to the added existing BarcodeLibCF project. Then you can use the class library as any other class you use.

    See the example project coming with the download or the svn/git code.

    Anything unclear?

    Josef

Leave a Reply