从DLL VBA导入类

时间:2017-10-29 22:05:05

标签: vba dll qr-code

我有一个(未注册的)DLL,我可以在VBA中访问,如下所示:

Declare Function IBarcodeReader Lib "C:\Users\myname\Downloads\interop\zxing.dll" () As Long

问题是,这适用于函数/ subs,但我想访问DLL中包含的类。

背景: 试图阅读pdf中嵌入的QRCodes。将PDF转换为Bitmap,然后在VBA中使用以下库: https://github.com/micjahn/ZXing.Net

1 个答案:

答案 0 :(得分:0)

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_To_QR_Code_To_File()
   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"

   Rem Or:

   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

来源:Using ZXing.Net with VBA

修改

re:注册DLL以便能够使用Class方法

看到/尝试过这些建议: