Jump to content

Search the Community

Showing results for tags 'autoit barcode generator'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Member Title


Location


WWW


Interests

Found 1 result

  1. Using BarCodeGenerator.dll in AutoIt: A Comprehensive Guide This guide introduces you to the BarCodeGenerator.dll—a dynamic link library designed for generating various types of barcodes and QR codes. You will learn about the structure of its exported functions, the necessary parameters, and how you can integrate and call these functions from an AutoIt script. The article also includes example code to illustrate both the in-memory image handling (using GDIPlus) as well as file-based output. 1. Exported Functions Overview The DLL exports two primary functions: a) CreateBarcode Purpose: Generates a barcode or QR code based on the provided text and other configuration parameters. Depending on the parameters, the function either returns an HBITMAP (when no file path is provided and when the output format is an image such as PNG, BMP, JPG, or TGA) or returns a text result with configuration details (for console output, SVG, or when output is generated to a file). Exported Signature (C/C++ Prototype): DLL_API void* __stdcall CreateBarcode( const wchar_t* textContent, const wchar_t* outputType, const wchar_t* eccStr, const wchar_t* qrColorHex, const wchar_t* bgColorHex, const wchar_t* outputFormat, const wchar_t* filePath, int sizeParam, int scale, int borderModules ); Parameters: textContent: The string content that you want to encode. For example, "Hello World". outputType: A string that defines the type of barcode/QR code. Accepted values include "qr", "code128", "code39", and "ean128". eccStr: Specifies the error correction level (primarily used for QR codes). Example values are "low", "medium", "quartile", and "high". qrColorHex and bgColorHex: These parameters represent the barcode (foreground) and background colors in hexadecimal notation. For example, passing "000000" for black and an empty string for the default background. outputFormat: Sets the desired output format. Valid options include "bmp", "png", "jpg", "jpeg", "tga", "svg", and "console". filePath: When provided with a valid path, the DLL saves the generated file to disk. If this parameter is an empty string, the function instead returns an HBITMAP (if the output is an image) that can be handled via GDIPlus in AutoIt. sizeParam: Indicates the desired overall size for the generated image. scale: The scale factor. If set to 0 (or less), the scale is determined automatically based on size and border parameters. borderModules: Determines the number of border modules (padding) around the generated symbol. Return Value: The function returns a pointer to a structure—BarcodeResult. This structure contains: A fixed-length wide-character array (wchar_t info[4096]) that includes the configuration details along with the generation result. A pointer (hBitmap) that will hold a valid HBITMAP if the output is generated in memory (i.e., when no file path is provided). b) GetBarcodeInfo Purpose: This function returns static information about the DLL, including version and author details. Exported Signature (C/C++ Prototype): DLL_API wchar_t* __stdcall GetBarcodeInfo(); Return Value: A pointer to a wide-character string containing DLL information (for example, version, author, etc.). 2. Structure Definition in the Header File For smooth integration with AutoIt, the DLL uses a predefined structure for the return value of CreateBarcode. Below is an example of the header file content (named BarCodeGenerator.h😞 #ifndef BARCODEGENERATOR_H #define BARCODEGENERATOR_H #ifdef _WIN32 #ifdef DLL_EXPORTS #define DLL_API __declspec(dllexport) #else #define DLL_API __declspec(dllimport) #endif #else #define DLL_API #endif // Define the size of the buffer to store info details. #define INFO_BUFFER_SIZE 4096 #ifdef __cplusplus extern "C" { #endif // Structure returned from CreateBarcode typedef struct _BarcodeResult { wchar_t info[INFO_BUFFER_SIZE]; #ifdef _WIN32 void* hBitmap; // HBITMAP handle on Windows platforms #else void* hBitmap; #endif } BarcodeResult; // Exported function to create a barcode/QR code. DLL_API void* __stdcall CreateBarcode( const wchar_t* textContent, const wchar_t* outputType, const wchar_t* eccStr, const wchar_t* qrColorHex, const wchar_t* bgColorHex, const wchar_t* outputFormat, const wchar_t* filePath, int sizeParam, int scale, int borderModules ); // Exported function to get general renderer information. DLL_API wchar_t* __stdcall GetBarcodeInfo(); #ifdef __cplusplus } #endif #endif // BARCODEGENERATOR_H This header file clearly defines the exported functions and makes it easier to write AutoIt scripts to call these functions via the DllCall mechanism. 3. Using the DLL in AutoIt When integrating this DLL in AutoIt, you must create a structure that matches BarcodeResult. Typically, you'll use DllStructCreate() with a format string such as "wchar[4096];ptr hBitmap". Example AutoIt Workflow: Call CreateBarcode to generate a QR code in memory. Pass an empty string as the filePath parameter so that the DLL returns an HBITMAP for in-memory processing. Use GDIPlus (via the GDIPlus UDF) to convert the HBITMAP to a PNG image and save it to disk. Call CreateBarcode to output directly to a file. Provide a valid filePath (e.g., "C:\Temp\qr_output.png") so that the DLL writes the file to the disk and also returns a text report with the configuration and operation details. Call GetBarcodeInfo to retrieve additional information about the DLL. Below is a sample AutoIt code snippet that demonstrates how to call these functions: #RequireAdmin ;~ #Region ;**** Directives created by AutoIt3Wrapper_GUI **** ;~ #AutoIt3Wrapper_UseX64=y ;~ #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ;~ #pragma compile(x64, true) ; For test FileDelete(@ScriptDir & "\output_qr.png") FileDelete(@ScriptDir & "\output_code128.png") ; Path to the DLL (adjust according to the actual location of the DLL on your system) Global Const $g_sDllPath = @AutoItX64 ? @ScriptDir & "\BarCodeGenerator_x64.dll" : @ScriptDir & "\BarCodeGenerator_x86.dll" ; Path to the DLL (update to the correct path) #include <GDIPlus.au3> ; Define the BarcodeResult structure as follows: ; - wchar[4096]: a text string containing configuration and result information (fixed at 4096 characters) ; - ptr hBitmap: the hBitmap pointer returned when using in-memory image output Local $tBarcodeResultDef = "wchar[4096];ptr hBitmap" ConsoleWrite("; EG 1 -----------------------------" & @CRLF) ; ----------------------------- ; PART 1: Call CreateBarcode to generate a QR code in-memory ; (Since FilePath is "" the function returns an HBITMAP, and the PNG image will be saved using _GDIPlus) Local $aRet = DllCall($g_sDllPath, "ptr", "CreateBarcode", _ "wstr", "Hello World", _ ; textContent "wstr", "qr", _ ; outputType "wstr", "medium", _ ; eccStr "wstr", "000000", _ ; qrColorHex "wstr", "", _ ; bgColorHex (empty means default) "wstr", "png", _ ; outputFormat "wstr", "", _ ; filePath = empty => create image in memory "int", 128, _ ; sizeParam "int", 0, _ ; scale "int", 1) ; borderModules If Not IsArray($aRet) Then ConsoleWrite("CreateBarcode call failed." & @CRLF) Else ; $aRet[0] is the pointer to the BarcodeResult structure. Local $pResult = $aRet[0] ; Map the returned pointer to the BarcodeResult structure. Local $sBarcodeResult = DllStructCreate($tBarcodeResultDef, $pResult) ; Retrieve the configuration and status message string. Local $sInfo = DllStructGetData($sBarcodeResult, 1) ConsoleWrite("In-memory QR generation result info:" & @CRLF & $sInfo & @CRLF) ; Get the HBITMAP Local $hBmp = DllStructGetData($sBarcodeResult, 2) If @error Then ConsoleWrite("! Error in DllStructGetData, Code: " & @error & @CRLF) EndIf ; Use _GDIPlus to save this HBITMAP to a PNG file. _GDIPlus_Startup() ; Convert HBITMAP to a GDI+ Bitmap object Local $hBmpGp = _GDIPlus_BitmapCreateFromHBITMAP($hBmp) If $hBmpGp = 0 Then ConsoleWrite("Failed to convert HBITMAP to GDI+ Bitmap." & @CRLF) Else ; Save the image to a file If _GDIPlus_ImageSaveToFile($hBmpGp, @ScriptDir & "\output_qr.png") Then ConsoleWrite("Saved in-memory QR code to file " & @ScriptDir & "\output_qr.png" & @CRLF) If FileExists(@ScriptDir & "\output_qr.png") Then ShellExecute(@ScriptDir & "\output_qr.png"); show qr Else ConsoleWrite("! Failed to save the image to file." & @CRLF) EndIf _GDIPlus_ImageDispose($hBmpGp) EndIf _GDIPlus_Shutdown() EndIf ConsoleWrite("; EG 2 -----------------------------" & @CRLF) ; ----------------------------- ; PART 2: Call CreateBarcode to output the result directly to a file. ; Here, since filePath is provided, the DLL will write the file to disk. Local $aRet2 = DllCall($g_sDllPath, "ptr", "CreateBarcode", _ "wstr", "Hello World", _ "wstr", "code128", _ "wstr", "medium", _ "wstr", "000000", _ "wstr", "", _ "wstr", "png", _ "wstr", @ScriptDir & "\output_code128.png", _ ; Direct output to file "int", 128, _ "int", 0, _ "int", 4) If Not IsArray($aRet2) Then ConsoleWrite("! File output CreateBarcode call failed." & @CRLF) Else Local $pResult2 = $aRet2[0] Local $sBarcodeResult2 = DllStructCreate($tBarcodeResultDef, $pResult2) Local $sInfo2 = DllStructGetData($sBarcodeResult2, 1) If FileExists(@ScriptDir & "\output_code128.png") Then ShellExecute(@ScriptDir & "\output_code128.png") ; show bar code 128 ConsoleWrite("File output QR generation result info:" & @CRLF & $sInfo2 & @CRLF) EndIf ConsoleWrite("; Test 3 -----------------------------" & @CRLF) ; ----------------------------- ; PART 3: Call GetBarcodeInfo to retrieve additional information about the author, version, etc. Local $aRet3 = DllCall($g_sDllPath, "wstr", "GetBarcodeInfo") If Not IsArray($aRet3) Then ConsoleWrite("! GetBarcodeInfo call failed." & @CRLF) Else MsgBox(64 + 262144, "About ", $aRet3[0] & @CRLF) ;MsgBox(64 + 262144, "GetBarcodeInfo: ", CorrectFromCP1252ToUTF8($aRet3[0]) & @CRLF) EndIf ; Function to convert strings misinterpreted as CP1252 to proper UTF-8 Func CorrectFromCP1252ToUTF8($sMisinterpreted) ; Convert the string (encoded as CP1252) to binary. Local $aBinary = StringToBinary($sMisinterpreted, 0) ; Create an ADODB.Stream object to perform encoding conversion. Local $oStream = ObjCreate("ADODB.Stream") If Not IsObj($oStream) Then MsgBox(16, "Error", "Unable to create ADODB.Stream object.") Return $sMisinterpreted EndIf ; Write the binary data to the stream. $oStream.Type = 1 ; 1: Binary $oStream.Open $oStream.Write($aBinary) ; Reset stream position and switch to text mode. $oStream.Position = 0 $oStream.Type = 2 ; 2: Text $oStream.Charset = "utf-8" ; Read data as UTF-8. Local $sCorrect = $oStream.ReadText() $oStream.Close() Return $sCorrect EndFunc ;==>CorrectFromCP1252ToUTF8 Explanation of the AutoIt Code: Structure Initialization: The structure for the result (BarcodeResult) is defined in AutoIt using DllStructCreate with "wchar[4096];ptr hBitmap". This matches the DLL’s definition. Function Calls: For the first call to CreateBarcode, an empty filePath tells the DLL to generate the image in memory. The returned HBITMAP is then processed via _GDIPlus for conversion and saving. For the second call, a valid file path is provided so the DLL writes the image file directly to disk while also returning a text-based log of the configuration and status. Finally, the static information is retrieved using GetBarcodeInfo. Output Display: Instead of using message boxes, all feedback and information are displayed using ConsoleWrite(). 4. Conclusion In this guide, we have covered the following: The structure and purpose of the exported functions from BarCodeGenerator.dll. Detailed descriptions of all necessary parameters—including text content, barcode/QR type, error correction level, colors, output format, and file handling. How to set up and call these functions from an AutoIt script using the DLL call mechanism. An example AutoIt code that demonstrates both in-memory image retrieval (with _GDIPlus) and direct file output, and how to retrieve additional DLL information. By following this guide, you should be able to effectively integrate the barcode generation capabilities of the DLL into your AutoIt projects and further customize the functionality to suit your requirements. Happy coding! _________________________________________ For Vietnamese: >> Link Download Dll/Exe (Because it contains exe cli file so to avoid warning when downloading I set password as number 1) Limitation: due to using c++17, it will not support running on windows XP ________________________________________________________ QR Code generator library (c) Nayuki
×
×
  • Create New...