This project has moved and is read-only. For the latest updates, please go here.

ZXing.Net in VBA

May 25, 2013 at 5:08 AM
In another thread, I ask for Working in VB6, know it can work on COM interop.
(I succeed work on VB6 via commandline assembly, thanks for Micjahn's information)
I think VBA also need to be work on COM interop.

I found many document talking about how about COM interop, still don't how make ZXing.Net work on COM interop (Sorry, I'm a newly in programming, only know about VB,net VB6 VBA)

I tried "RegAsm ZXing.dll /tlb /codebase",
and I tried "Set MyVBzxing = CreateObject("ZXing.BarcodeReader"),
not work at both (I used net2.0 assembly)

I don't how to assembly ZXing.Net to COM interop in C# source code.

Any body can help to make a COM interop or ActiveX DLL assembly version for ZXing.Net ?
May 26, 2013 at 7:41 PM
I made a small test with ZXing.Net and VB6. It works:
  1. open a command prompt and execute the following: regasm zxing.dll /codebase /tlb:zxing.tlb
  2. open a VB6 project and go to the "References"
  3. open the zxing.tlb file and add it as a reference (the name is a little bit unconventional: "port of the java based barcode scanning library for .net...")
  4. now create an instance:
    Dim reader As BarcodeReader
    Set reader = new BarcodeReader()
    reader.decode(...)
It should work the same way for VBA, I think.
May 29, 2013 at 4:57 AM
Edited May 29, 2013 at 12:43 PM
I got some error message on Step 1, please, is it normal ?
When I enter the "regasm zxing.dll /codebase /tlb:zxing.tlb" in command prompt"
Type has been successfully registered
Type library export tool in dealing with 'ZXing.IBarcodeReaderGeneric `1, zxing' when the warning. Warning
: Type library exporter encountered a generic type. Generic class can not be exposed to the COM.
Type library export tool in dealing with 'ZXing.IMultipleBarcodeReaderGeneric `1, zxing' when police
Reports. Warning: The type library exporter encountered a generic type. Generic class can not be exposed to the COM.
Type library export tool in dealing with 'ZXing.BarcodeReaderGeneric `1, zxing' when the warning. Warning:
 Type library exporter encountered a generic type. Generic class can not be exposed to the COM.
.
.
.
Type library export tool in dealing with 'ZXing.IMultipleBarcodeReader.get_PossibleFormats (# 0),
zxing 'with warnings. Warning: The type library exporter encountered in the signature generic type instance. Generic Process Sigma can not be exported to COM.
Type library export tool in dealing with 'ZXing.IMultipleBarcodeReader.set_PossibleFormats (value
), Zxing 'when the warning. Warning: The type library exporter encountered in the signature generic type instance. Generics The code can not be exported to COM.
Components have been exported to 'zxing.tlb', and type libraries have successfully logged
May 29, 2013 at 12:14 PM
That are only warnings because generic types can't be exported.

You can ignore them.
May 29, 2013 at 12:45 PM
Thank you ! ....... I going to try it !
Aug 10, 2015 at 2:29 PM
micjahn wrote:
I made a small test with ZXing.Net and VB6. It works:
  1. open a command prompt and execute the following: regasm zxing.dll /codebase /tlb:zxing.tlb
  2. open a VB6 project and go to the "References"
  3. open the zxing.tlb file and add it as a reference (the name is a little bit unconventional: "port of the java based barcode scanning library for .net...")
  4. now create an instance:
    Dim reader As BarcodeReader
    Set reader = new BarcodeReader()
    reader.decode(...)
It should work the same way for VBA, I think.
Hi,
Please post a sample with VB6.
Thank you very much.
Apr 29 at 6:37 PM
little small update on that:
part of version 0.16 of ZXing.Net is a specialized Assembly which can be easily used with VBA.
At the moment it's only available as source. if someone wants to try it out you have to build the assembly yourself.

With the zxing.interop.dll you can to things like the following:
Option Compare Database

Function Decode_QR_Code_From_File()
   Dim reader As IBarcodeReader
   Dim res As Result

   Set reader = New BarcodeReader

   reader.options.PossibleFormats.Add BarcodeFormat_QR_CODE

   Set res = reader.DecodeImageFile("D:\Barcodes\QrCodes\www.png")
End Function

Function Decode_QR_Code_From_Byte_Array()
   Dim reader As IBarcodeReader
   Dim rawRGB(1000) As Byte
   Dim res As Result

   Set reader = New BarcodeReader

   reader.options.PossibleFormats.Add BarcodeFormat_QR_CODE

   Rem TODO: load bitmap data to byte array rawRGB
   Set res = reader.DecodeImageBytes(rawRGB, 10, 10, BitmapFormat.BitmapFormat_Gray8)
End Function

Function Encode()
   Dim writer As IBarcodeWriter
   Dim qrCodeOptions As QrCodeEncodingOptions
   Dim pixelDataResult As PixelData

   Set qrCodeOptions = New QrCodeEncodingOptions
   Set writer = New BarcodeWriter
   writer.Format = BarcodeFormat_QR_CODE
   Set writer.options = qrCodeOptions
   qrCodeOptions.Height = 100
   qrCodeOptions.Width = 100
   qrCodeOptions.CharacterSet = "UTF-8"
   qrCodeOptions.Margin = 10
   qrCodeOptions.ErrorCorrection = ErrorCorrectionLevel_H

   writer.WritePngToFile "Test", "D:\interop_qrcode.png"

   Set pixelDataResult = writer.Write("Test")
End Function


Function Decode_QR_Code_From_File_CreateObject()
   Dim reader As IBarcodeReader
   Dim res As Result

   Set reader = CreateObject("ZXing.Interop.Decoding.BarcodeReader")

   reader.options.PossibleFormats.Add BarcodeFormat_QR_CODE

   Set res = reader.DecodeImageFile("D:\Barcodes\QrCodes\www.png")
End Function