Popular Post UEZ Posted June 30, 2022 Popular Post Posted June 30, 2022 (edited) Here a first draft for creating barcodes using the Zint.dll (v2.15.09). Mor information about Zint can be found here: https://zint.org.uk Zint, libzint and Zint Barcode Studio are Copyright © 2022 Robin Stuart. All historical versions are distributed under the GNU General Public License version 3 or later. Version 2.5 (and later) is released under a dual license: the encoding library is released under the BSD license whereas the GUI, Zint Barcode Studio, is released under the GNU General Public License version 3 or later. The code became too long to post here! -> Download from my OneDrive: Zint Zint.au3 expandcollapse popup;Coded by UEZ ;v0.60 build 2025-09-14 beta ;IMPORTANT: You are not allowed to sell this code or just parts of it in a commercial project or modify it and distribute it with a different name! ; Distributing copies of the program in compiled format (exe) must be free of any fee! #include-once #include "ZintDll.au3" Global $g__ZintDLL = @AutoItX64 ? (@ScriptDir & "\Zint64.dll") : (@ScriptDir & "\Zint.dll") #Region Constances ; === Barcode Symbologies === Global Const $BARCODE_CODE11 = 1 ; Code 11 Global Const $BARCODE_C25STANDARD = 2 ; 2 of 5 Standard (Matrix) Global Const $BARCODE_C25MATRIX = 2 ; Legacy Global Const $BARCODE_C25INTER = 3 ; 2 of 5 Interleaved Global Const $BARCODE_C25IATA = 4 ; 2 of 5 IATA Global Const $BARCODE_C25LOGIC = 6 ; 2 of 5 Data Logic Global Const $BARCODE_C25IND = 7 ; 2 of 5 Industrial Global Const $BARCODE_CODE39 = 8 ; Code 39 Global Const $BARCODE_EXCODE39 = 9 ; Extended Code 39 Global Const $BARCODE_EAN8 = 10 ; EAN-8 (GTIN-8) Global Const $BARCODE_EAN_2ADDON = 11 ; EAN/UPC 2-digit add-on Global Const $BARCODE_EAN_5ADDON = 12 ; EAN/UPC 5-digit add-on Global Const $BARCODE_EANX = 13 ; Legacy Global Const $BARCODE_EANX_CHK = 14 ; Legacy Global Const $BARCODE_EAN13 = 15 ; EAN-13 (GTIN-13) Global Const $BARCODE_GS1_128 = 16 ; GS1-128 Global Const $BARCODE_EAN128 = 16 ; Legacy Global Const $BARCODE_CODABAR = 18 ; Codabar Global Const $BARCODE_CODE128 = 20 ; Code 128 Global Const $BARCODE_DPLEIT = 21 ; Deutsche Post Leitcode Global Const $BARCODE_DPIDENT = 22 ; Deutsche Post Identcode Global Const $BARCODE_CODE16K = 23 ; Code 16k Global Const $BARCODE_CODE49 = 24 ; Code 49 Global Const $BARCODE_CODE93 = 25 ; Code 93 Global Const $BARCODE_FLAT = 28 ; Flattermarken Global Const $BARCODE_DBAR_OMN = 29 ; GS1 DataBar Omnidirectional Global Const $BARCODE_RSS14 = 29 ; Legacy Global Const $BARCODE_DBAR_LTD = 30 ; GS1 DataBar Limited Global Const $BARCODE_RSS_LTD = 30 ; Legacy Global Const $BARCODE_DBAR_EXP = 31 ; GS1 DataBar Expanded Global Const $BARCODE_RSS_EXP = 31 ; Legacy Global Const $BARCODE_TELEPEN = 32 ; Telepen Alpha Global Const $BARCODE_UPCA = 34 ; UPC-A Global Const $BARCODE_UPCA_CHK = 35 ; UPC-A including check digit Global Const $BARCODE_UPCE = 37 ; UPC-E Global Const $BARCODE_UPCE_CHK = 38 ; UPC-E including check digit Global Const $BARCODE_POSTNET = 40 ; USPS POSTNET Global Const $BARCODE_MSI_PLESSEY = 47 ; MSI Plessey Global Const $BARCODE_FIM = 49 ; Facing Identification Mark Global Const $BARCODE_LOGMARS = 50 ; LOGMARS Global Const $BARCODE_PHARMA = 51 ; Pharmacode One-Track Global Const $BARCODE_PZN = 52 ; Pharmazentralnummer Global Const $BARCODE_PHARMA_TWO = 53 ; Pharmacode Two-Track Global Const $BARCODE_CEPNET = 54 ; Brazilian CEPNet Postal Code Global Const $BARCODE_PDF417 = 55 ; PDF417 Global Const $BARCODE_PDF417COMP = 56 ; Compact PDF417 Global Const $BARCODE_PDF417TRUNC = 56 ; Legacy Global Const $BARCODE_MAXICODE = 57 ; MaxiCode Global Const $BARCODE_QRCODE = 58 ; QR Code Global Const $BARCODE_CODE128AB = 60 ; Code 128 (Suppress Code Set C) Global Const $BARCODE_CODE128B = 60 ; Legacy Global Const $BARCODE_AUSPOST = 63 ; Australia Post Standard Customer Global Const $BARCODE_AUSREPLY = 66 ; Australia Post Reply Paid Global Const $BARCODE_AUSROUTE = 67 ; Australia Post Routing Global Const $BARCODE_AUSREDIRECT = 68 ; Australia Post Redirection Global Const $BARCODE_ISBNX = 69 ; ISBN Global Const $BARCODE_RM4SCC = 70 ; Royal Mail 4-State Global Const $BARCODE_DATAMATRIX = 71 ; Data Matrix (ECC200) Global Const $BARCODE_EAN14 = 72 ; EAN-14 Global Const $BARCODE_VIN = 73 ; Vehicle Identification Number Global Const $BARCODE_CODABLOCKF = 74 ; Codablock-F Global Const $BARCODE_NVE18 = 75 ; NVE-18 (SSCC-18) Global Const $BARCODE_JAPANPOST = 76 ; Japanese Postal Code Global Const $BARCODE_KOREAPOST = 77 ; Korea Post Global Const $BARCODE_DBAR_STK = 79 ; GS1 DataBar Stacked Global Const $BARCODE_RSS14STACK = 79 ; Legacy Global Const $BARCODE_DBAR_OMNSTK = 80 ; GS1 DataBar Stacked Omnidirectional Global Const $BARCODE_RSS14STACK_OMNI = 80 ; Legacy Global Const $BARCODE_DBAR_EXPSTK = 81 ; GS1 DataBar Expanded Stacked Global Const $BARCODE_RSS_EXPSTACK = 81 ; Legacy Global Const $BARCODE_PLANET = 82 ; USPS PLANET Global Const $BARCODE_MICROPDF417 = 84 ; MicroPDF417 Global Const $BARCODE_USPS_IMAIL = 85 ; USPS Intelligent Mail Global Const $BARCODE_ONECODE = 85 ; Legacy Global Const $BARCODE_PLESSEY = 86 ; UK Plessey Global Const $BARCODE_TELEPEN_NUM = 87 ; Telepen Numeric Global Const $BARCODE_ITF14 = 89 ; ITF-14 Global Const $BARCODE_KIX = 90 ; Dutch Post KIX Global Const $BARCODE_AZTEC = 92 ; Aztec Global Const $BARCODE_DAFT = 93 ; DAFT Global Const $BARCODE_DPD = 96 ; DPD Global Const $BARCODE_MICROQR = 97 ; Micro QR Global Const $BARCODE_HIBC_128 = 98 ; HIBC Code 128 Global Const $BARCODE_HIBC_39 = 99 ; HIBC Code 39 Global Const $BARCODE_HIBC_DM = 102 ; HIBC Data Matrix Global Const $BARCODE_HIBC_QR = 104 ; HIBC QR Global Const $BARCODE_HIBC_PDF = 106 ; HIBC PDF417 Global Const $BARCODE_HIBC_MICPDF = 108 ; HIBC MicroPDF417 Global Const $BARCODE_HIBC_BLOCKF = 110 ; HIBC Codablock-F Global Const $BARCODE_HIBC_AZTEC = 112 ; HIBC Aztec Global Const $BARCODE_DOTCODE = 115 ; DotCode Global Const $BARCODE_HANXIN = 116 ; Han Xin Global Const $BARCODE_MAILMARK_2D = 119 ; Royal Mail 2D Mailmark Global Const $BARCODE_UPU_S10 = 120 ; UPU S10 Global Const $BARCODE_MAILMARK_4S = 121 ; Royal Mail 4-State Mailmark Global Const $BARCODE_MAILMARK = 121 ; Legacy Global Const $BARCODE_AZRUNE = 128 ; Aztec Runes Global Const $BARCODE_CODE32 = 129 ; Code 32 Global Const $BARCODE_EANX_CC = 130 ; Legacy Global Const $BARCODE_GS1_128_CC = 131 ; GS1-128 Composite Global Const $BARCODE_EAN128_CC = 131 ; Legacy Global Const $BARCODE_DBAR_OMN_CC = 132 ; DataBar Omnidirectional Composite Global Const $BARCODE_RSS14_CC = 132 ; Legacy Global Const $BARCODE_DBAR_LTD_CC = 133 ; DataBar Limited Composite Global Const $BARCODE_RSS_LTD_CC = 133 ; Legacy Global Const $BARCODE_DBAR_EXP_CC = 134 ; DataBar Expanded Composite Global Const $BARCODE_RSS_EXP_CC = 134 ; Legacy Global Const $BARCODE_UPCA_CC = 135 ; UPC-A Composite Global Const $BARCODE_UPCE_CC = 136 ; UPC-E Composite Global Const $BARCODE_DBAR_STK_CC = 137 ; DataBar Stacked Composite Global Const $BARCODE_RSS14STACK_CC = 137 ; Legacy Global Const $BARCODE_DBAR_OMNSTK_CC = 138 ; DataBar Stacked Omnidirectional Composite Global Const $BARCODE_RSS14_OMNI_CC = 138 ; Legacy Global Const $BARCODE_DBAR_EXPSTK_CC = 139 ; DataBar Expanded Stacked Composite Global Const $BARCODE_RSS_EXPSTACK_CC = 139 ; Legacy Global Const $BARCODE_CHANNEL = 140 ; Channel Code Global Const $BARCODE_CODEONE = 141 ; Code One Global Const $BARCODE_GRIDMATRIX = 142 ; Grid Matrix Global Const $BARCODE_UPNQR = 143 ; UPNQR Global Const $BARCODE_ULTRA = 144 ; Ultracode Global Const $BARCODE_RMQR = 145 ; Rectangular Micro QR Global Const $BARCODE_BC412 = 146 ; IBM BC412 Global Const $BARCODE_DXFILMEDGE = 147 ; DX Film Edge Global Const $BARCODE_EAN8_CC = 148 ; EAN-8 Composite Global Const $BARCODE_EAN13_CC = 149 ; EAN-13 Composite Global Const $BARCODE_LAST = 149 ; Max marker ; === Output options === Global Const $BARCODE_BIND_TOP = 0x00001 ; Bind top Global Const $BARCODE_BIND = 0x00002 ; Bind bottom Global Const $BARCODE_BOX = 0x00004 ; Box around symbol Global Const $BARCODE_STDOUT = 0x00008 ; Output to stdout Global Const $READER_INIT = 0x00010 ; Reader Initialisation Global Const $SMALL_TEXT = 0x00020 ; Small human readable text Global Const $BOLD_TEXT = 0x00040 ; Bold human readable text Global Const $CMYK_COLOUR = 0x00080 ; Use CMYK in EPS Global Const $BARCODE_DOTTY_MODE = 0x00100 ; Dotty mode Global Const $GS1_GS_SEPARATOR = 0x00200 ; Use GS as separator Global Const $OUT_BUFFER_INTERMEDIATE = 0x00400 ; Return intermediate data Global Const $BARCODE_QUIET_ZONES = 0x00800 ; Force quiet zones Global Const $BARCODE_NO_QUIET_ZONES = 0x01000 ; Suppress quiet zones Global Const $COMPLIANT_HEIGHT = 0x02000 ; Compliant height Global Const $EANUPC_GUARD_WHITESPACE = 0x04000 ; Guard whitespace Global Const $EMBED_VECTOR_FONT = 0x08000 ; Embed vector font Global Const $BARCODE_MEMORY_FILE = 0x10000 ; Output to memory Global Const $BARCODE_RAW_TEXT = 0x20000 ; Output raw text ; === Input modes === Global Const $DATA_MODE = 0 ; Binary input Global Const $UNICODE_MODE = 1 ; Unicode input Global Const $GS1_MODE = 2 ; GS1 input Global Const $ESCAPE_MODE = 0x0008 ; Escape sequences Global Const $GS1PARENS_MODE = 0x0010 ; GS1 parentheses Global Const $GS1NOCHECK_MODE = 0x0020 ; Skip GS1 checks Global Const $HEIGHTPERROW_MODE = 0x0040 ; Height per row Global Const $FAST_MODE = 0x0080 ; Fast mode Global Const $EXTRA_ESCAPE_MODE = 0x0100 ; Extra escape Global Const $GS1SYNTAXENGINE_MODE = 0x0200 ; GS1 syntax engine ; === Data Matrix options === Global Const $DM_SQUARE = 100 ; Square only Global Const $DM_DMRE = 101 ; DMRE only Global Const $DM_ISO_144 = 128 ; ISO 144 compliance ; === QR/Han Xin/Grid Matrix options === Global Const $ZINT_FULL_MULTIBYTE = 200 ; Full multibyte ; === Ultracode options === Global Const $ULTRA_COMPRESSION = 128 ; Compression mode ; === Warnings & Errors === Global Const $ZINT_WARN_HRT_TRUNCATED = 1 ; HRT truncated Global Const $ZINT_WARN_INVALID_OPTION = 2 ; Invalid option Global Const $ZINT_WARN_USES_ECI = 3 ; Uses ECI Global Const $ZINT_WARN_NONCOMPLIANT = 4 ; Noncompliant symbol Global Const $ZINT_ERROR = 5 ; General error Global Const $ZINT_ERROR_TOO_LONG = 5 ; Data too long Global Const $ZINT_ERROR_INVALID_DATA = 6 ; Invalid data Global Const $ZINT_ERROR_INVALID_CHECK = 7 ; Invalid check digit Global Const $ZINT_ERROR_INVALID_OPTION = 8 ; Invalid option Global Const $ZINT_ERROR_ENCODING_PROBLEM = 9 ; Encoding problem Global Const $ZINT_ERROR_FILE_ACCESS = 10 ; File access error Global Const $ZINT_ERROR_MEMORY = 11 ; Memory error Global Const $ZINT_ERROR_FILE_WRITE = 12 ; File write error Global Const $ZINT_ERROR_USES_ECI = 13 ; Uses ECI Global Const $ZINT_ERROR_NONCOMPLIANT = 14 ; Noncompliant Global Const $ZINT_ERROR_HRT_TRUNCATED = 15 ; HRT truncated ; === Warning levels === Global Const $WARN_DEFAULT = 0 ; Default warnings Global Const $WARN_FAIL_ALL = 2 ; Treat all warnings as errors ; === Capabilities === Global Const $ZINT_CAP_HRT = 0x0001 ; Has HRT Global Const $ZINT_CAP_STACKABLE = 0x0002 ; Stackable Global Const $ZINT_CAP_EANUPC = 0x0004 ; EAN/UPC Global Const $ZINT_CAP_EXTENDABLE = 0x0004 ; Extendable (legacy) Global Const $ZINT_CAP_COMPOSITE = 0x0008 ; Composite Global Const $ZINT_CAP_ECI = 0x0010 ; ECI capable Global Const $ZINT_CAP_GS1 = 0x0020 ; GS1 capable Global Const $ZINT_CAP_DOTTY = 0x0040 ; Dotty capable Global Const $ZINT_CAP_QUIET_ZONES = 0x0080 ; Quiet zones Global Const $ZINT_CAP_FIXED_RATIO = 0x0100 ; Fixed ratio Global Const $ZINT_CAP_READER_INIT = 0x0200 ; Reader Init Global Const $ZINT_CAP_FULL_MULTIBYTE = 0x0400 ; Full multibyte Global Const $ZINT_CAP_MASK = 0x0800 ; Masking Global Const $ZINT_CAP_STRUCTAPP = 0x1000 ; Structured Append Global Const $ZINT_CAP_COMPLIANT_HEIGHT = 0x2000 ; Compliant height Global Const $ZINT_CAP_BINDABLE = 0x4000 ; Bindable ; === Limits === Global Const $ZINT_MAX_DATA_LEN = 17400 ; Max data length Global Const $ZINT_MAX_SEG_COUNT = 256 ; Max segment count #EndRegion #Region Structs ; Vector elements Global Const $tag_zint_vector_rect = "struct;" & _ "float x;" & _ ; Top left "float y;" & _ "float height;" & _ "float width;" & _ "long colour;" & _ ; -1 foreground, 1-8 = Cyan, Blue, Magenta, Red, Yellow, Green, Black, White "ptr next;" & _ ; Pointer to next rectangle "endstruct" Global Const $tag_zint_vector_hexagon = "struct;" & _ "float x;" & _ ; Centre x "float y;" & _ ; Centre y "float diameter;" & _ ; Short diameter (inscribed circle) "long rotation;" & _ ; 0, 90, 180, 270 (0 = apex at top) "ptr next;" & _ ; Pointer to next hexagon "endstruct" Global Const $tag_zint_vector_string = "struct;" & _ "float x;" & _ ; Relative to halign "float y;" & _ ; Relative to baseline "float fsize;" & _ ; Font size "float width;" & _ ; Rendered width estimate "long length;" & _ ; Number of characters (bytes) "long rotation;" & _ ; 0, 90, 180, 270 "long halign;" & _ ; 0 = centre, 1 = left, 2 = right "ptr text;" & _ ; UTF-8, NUL-terminated "ptr next;" & _ ; Pointer to next string "endstruct" Global Const $tag_zint_vector_circle = "struct;" & _ "float x;" & _ ; Centre x "float y;" & _ ; Centre y "float diameter;" & _ ; Circle diameter (excludes width) "float width;" & _ ; Perimeter width, 0 = fill "long colour;" & _ ; 0 = foreground colour, else background "ptr next;" & _ ; Pointer to next circle "endstruct" Global Const $tag_zint_vector = "struct;" & _ "float width;" & _ ; Overall barcode width "float height;" & _ ; Overall barcode height "ptr rectangles;" & _ ; Pointer to first rectangle "ptr hexagons;" & _ ; Pointer to first hexagon "ptr strings;" & _ ; Pointer to first string "ptr circles;" & _ ; Pointer to first circle "endstruct" ; Structured Append info Global Const $tag_zint_structapp = "long index;" & _ ; Position in sequence (1-based) "long count;" & _ ; Number of symbols in sequence "char id[32];" ; Optional ID, ASCII, NUL-terminated ; Segment info Global Const $tag_zint_seg = "struct;" & _ "ptr source;" & _ ; Data pointer "long length;" & _ ; Data length (0 = NUL-terminated) "long eci;" & _ ; Extended Channel Interpretation "endstruct" ; Main symbol structure Global Const $tag_zint_symbol = "struct;" & _ "long symbology;" & _ ; Symbol type "float height;" & _ ; Barcode height "float scale;" & _ ; Scale factor "long whitespace_width;" & _ ; Horizontal whitespace "long whitespace_height;" & _ ; Vertical whitespace "long border_width;" & _ ; Border width "long output_options;" & _ ; Output options "char fgcolour[16];" & _ ; Foreground colour string "char bgcolour[16];" & _ ; Background colour string "ptr fgcolor;" & _ ; Pointer to fgcolour "ptr bgcolor;" & _ ; Pointer to bgcolour "char outfile[256];" & _ ; Output filename "char primary[128];" & _ ; Primary message data "long option_1;" & _ ; Symbol-specific option "long option_2;" & _ "long option_3;" & _ "long show_hrt;" & _ ; Show (1) / hide (0) human readable text "long input_mode;" & _ ; Input encoding "long eci;" & _ ; Extended Channel Interpretation "float dpmm;" & _ ; Resolution in dots/mm "float dot_size;" & _ ; Dot size (dotty mode) "float text_gap;" & _ ; Gap between barcode and text "float guard_descent;" & _ ; EAN/UPC guard bar descent $tag_zint_structapp & _ ; Structured append info "long warn_level;" & _ ; Warning behaviour "long debug;" & _ ; Debug flags "byte text[256];" & _ ; Human-readable text (output) "long text_length;" & _ ; Length of text (output) "long rows;" & _ ; Number of rows (output) "long width;" & _ ; Symbol width (output) "byte encoded_data[28800];" & _ ; Encoded data (flattened 200x144) "float row_height[200];" & _ ; Row heights "char errtxt[160];" & _ ; Error text (output) "ptr bitmap;" & _ ; Bitmap pointer (output) "long bitmap_width;" & _ ; Bitmap width "long bitmap_height;" & _ ; Bitmap height "ptr alphamap;" & _ ; Alpha channel pointer "ptr vector;" & _ ; Vector header pointer "ptr memfile;" & _ ; In-memory file buffer "long memfile_size;" & _ ; Buffer length "ptr raw_segs;" & _ ; Raw segments pointer "long raw_seg_count;" & _ ; Number of raw segs "endstruct" #EndRegion #Region Functions ; Create and initialize a symbol structure Func ZBarcode_Create() If Not FileExists($g__ZintDLL) Then If @AutoItX64 Then _zint64dll(True) Else _zintdll(True) EndIf EndIf Local $hPtr = DllCall($g__ZintDLL, "ptr:cdecl", "ZBarcode_Create")[0] If $hPtr = 0 Then Return SetError(2, 0, 0) Return $hPtr EndFunc ; Free any output buffers that may have been created and initialize output fields Func ZBarcode_Clear($pSymbol) If IsPtr($pSymbol) And $pSymbol <> 0 Then DllCall($g__ZintDLL, "none:cdecl", "ZBarcode_Clear", "ptr", $pSymbol) Return 1 EndIf Return SetError(1, 0, 0) EndFunc ; Free any output buffers that may have been created and reset all fields to defaults Func ZBarcode_Reset($pSymbol) If IsPtr($pSymbol) And $pSymbol <> 0 Then DllCall($g__ZintDLL, "none:cdecl", "ZBarcode_Reset", "ptr", $pSymbol) Return 1 EndIf Return SetError(1, 0, 0) EndFunc ; Free a symbol structure, including any output buffers Func ZBarcode_Delete($pSymbol) If IsPtr($pSymbol) And $pSymbol <> 0 Then DllCall($g__ZintDLL, "none:cdecl", "ZBarcode_Delete", "ptr", $pSymbol) Return 1 EndIf Return SetError(1, 0, 0) EndFunc ; =================================================================== ; Encoding ; =================================================================== ; Encode a barcode. If length is 0 or negative, source must be NUL-terminated Func ZBarcode_Encode($pSymbol, $sInput) Local $iLength = StringLen($sInput) Local $tInput = DllStructCreate("struct;ubyte text[" & $iLength + 1 & "];endstruct") $tInput.text = $sInput Local $iResult = DllCall($g__ZintDLL, "long:cdecl", "ZBarcode_Encode", "ptr", $pSymbol, "struct*", $tInput, "long", $iLength + 1)[0] If $iResult Then Return SetError($iResult, 0, 0) Return 1 EndFunc ; Encode a barcode with multiple ECI segments Func ZBarcode_Encode_Segs($pSymbol, $pSegs, $iSegCount) Local $iResult = DllCall($g__ZintDLL, "long:cdecl", "ZBarcode_Encode_Segs", "ptr", $pSymbol, "ptr", $pSegs, "long", $iSegCount)[0] If $iResult Then Return SetError($iResult, 0, 0) Return 1 EndFunc ; Encode a barcode using input data from file Func ZBarcode_Encode_File($pSymbol, $sFilename) Local $iResult = DllCall($g__ZintDLL, "long:cdecl", "ZBarcode_Encode_File", "ptr", $pSymbol, "str", $sFilename)[0] If $iResult Then Return SetError($iResult, 0, 0) Return 1 EndFunc ; =================================================================== ; Output to file ; =================================================================== ; Output a previously encoded symbol to file Func ZBarcode_Print($pSymbol, $iAngle = 0) Local $iResult = DllCall($g__ZintDLL, "long:cdecl", "ZBarcode_Print", "ptr", $pSymbol, "long", $iAngle)[0] If $iResult Then Return SetError($iResult, 0, 0) Return 1 EndFunc ; Encode and output a symbol to file Func ZBarcode_Encode_and_Print($pSymbol, $sInput, $iRotate = 0) Local $iLength = StringLen($sInput) Local $tInput = DllStructCreate("struct;ubyte text[" & $iLength + 1 & "];endstruct") $tInput.text = $sInput Local $iResult = DllCall($g__ZintDLL, "long:cdecl", "ZBarcode_Encode_and_Print", "ptr", $pSymbol, "struct*", $tInput, "long", $iLength + 1, "long", $iRotate)[0] If $iResult Then Return SetError($iResult, 0, 0) Return 1 EndFunc ; Encode a symbol with multiple ECI segments and output to file Func ZBarcode_Encode_Segs_and_Print($pSymbol, $pSegs, $iSegCount, $iRotate = 0) Local $iResult = DllCall($g__ZintDLL, "long:cdecl", "ZBarcode_Encode_Segs_and_Print", "ptr", $pSymbol, "ptr", $pSegs, "long", $iSegCount, "long", $iRotate)[0] If $iResult Then Return SetError($iResult, 0, 0) Return 1 EndFunc ; Encode a symbol using input data from file and output to file Func ZBarcode_Encode_File_and_Print($pSymbol, $sFilename, $iRotate = 0) Local $iResult = DllCall($g__ZintDLL, "long:cdecl", "ZBarcode_Encode_File_and_Print", "ptr", $pSymbol, "str", $sFilename, "long", $iRotate)[0] If $iResult Then Return SetError($iResult, 0, 0) Return 1 EndFunc ; =================================================================== ; Output to memory (raster/vector) ; =================================================================== Func ZBarcode_Buffer($pSymbol, $iAngle = 0) Local $iResult = DllCall($g__ZintDLL, "long:cdecl", "ZBarcode_Buffer", "ptr", $pSymbol, "long", $iAngle)[0] If $iResult Then Return SetError($iResult, 0, 0) Return 1 EndFunc Func ZBarcode_Encode_and_Buffer($pSymbol, $sInput, $iRotate = 0) Local $iLength = StringLen($sInput) Local $tInput = DllStructCreate("struct;ubyte text[" & $iLength + 1 & "];endstruct") $tInput.text = $sInput Local $iResult = DllCall($g__ZintDLL, "long:cdecl", "ZBarcode_Encode_and_Buffer", "ptr", $pSymbol, "struct*", $tInput, "long", $iLength + 1, "long", $iRotate)[0] If $iResult Then Return SetError($iResult, 0, 0) Return 1 EndFunc Func ZBarcode_Encode_Segs_and_Buffer($pSymbol, $pSegs, $iSegCount, $iRotate = 0) Local $iResult = DllCall($g__ZintDLL, "long:cdecl", "ZBarcode_Encode_Segs_and_Buffer", "ptr", $pSymbol, "ptr", $pSegs, "long", $iSegCount, "long", $iRotate)[0] If $iResult Then Return SetError($iResult, 0, 0) Return 1 EndFunc Func ZBarcode_Encode_File_and_Buffer($pSymbol, $sFilename, $iRotate = 0) Local $iResult = DllCall($g__ZintDLL, "long:cdecl", "ZBarcode_Encode_File_and_Buffer", "ptr", $pSymbol, "str", $sFilename, "long", $iRotate)[0] If $iResult Then Return SetError($iResult, 0, 0) Return 1 EndFunc Func ZBarcode_Buffer_Vector($pSymbol, $iAngle = 0) Local $iResult = DllCall($g__ZintDLL, "long:cdecl", "ZBarcode_Buffer_Vector", "ptr", $pSymbol, "long", $iAngle)[0] If $iResult Then Return SetError($iResult, 0, 0) Return 1 EndFunc Func ZBarcode_Encode_and_Buffer_Vector($pSymbol, $sInput, $iRotate = 0) Local $iLength = StringLen($sInput) Local $tInput = DllStructCreate("struct;ubyte text[" & $iLength + 1 & "];endstruct") $tInput.text = $sInput Local $iResult = DllCall($g__ZintDLL, "long:cdecl", "ZBarcode_Encode_and_Buffer_Vector", "ptr", $pSymbol, "struct*", $tInput, "long", $iLength + 1, "long", $iRotate)[0] If $iResult Then Return SetError($iResult, 0, 0) Return 1 EndFunc Func ZBarcode_Encode_Segs_and_Buffer_Vector($pSymbol, $pSegs, $iSegCount, $iRotate = 0) Local $iResult = DllCall($g__ZintDLL, "long:cdecl", "ZBarcode_Encode_Segs_and_Buffer_Vector", "ptr", $pSymbol, "ptr", $pSegs, "long", $iSegCount, "long", $iRotate)[0] If $iResult Then Return SetError($iResult, 0, 0) Return 1 EndFunc Func ZBarcode_Encode_File_and_Buffer_Vector($pSymbol, $sFilename, $iRotate = 0) Local $iResult = DllCall($g__ZintDLL, "long:cdecl", "ZBarcode_Encode_File_and_Buffer_Vector", "ptr", $pSymbol, "str", $sFilename, "long", $iRotate)[0] If $iResult Then Return SetError($iResult, 0, 0) Return 1 EndFunc ; =================================================================== ; Info & Validation ; =================================================================== ; Is symbol_id a recognized symbology? Func ZBarcode_ValidID($iSymbolID) Return DllCall($g__ZintDLL, "long:cdecl", "ZBarcode_ValidID", "long", $iSymbolID)[0] EndFunc ; Copy BARCODE_XXX name of symbol_id into name buffer Func ZBarcode_BarcodeName($iSymbolID) Local $tName = DllStructCreate("char[32]") Local $iResult = DllCall($g__ZintDLL, "long:cdecl", "ZBarcode_BarcodeName", "long", $iSymbolID, "struct*", $tName)[0] If $iResult Then Return SetError($iResult, 0, "") Return DllStructGetData($tName, 1) EndFunc ; Return the capability flags for symbology symbol_id that match cap_flag Func ZBarcode_Cap($iSymbolID, $iCapFlag) Return DllCall($g__ZintDLL, "uint:cdecl", "ZBarcode_Cap", "long", $iSymbolID, "uint", $iCapFlag)[0] EndFunc ; =================================================================== ; X-dimension & Scaling ; =================================================================== Func ZBarcode_Default_Xdim($iSymbolID) Return DllCall($g__ZintDLL, "float:cdecl", "ZBarcode_Default_Xdim", "long", $iSymbolID)[0] EndFunc Func ZBarcode_Scale_From_XdimDp($iSymbolID, $fXDimMM, $fDpmm, $sFiletype = "") Return DllCall($g__ZintDLL, "float:cdecl", "ZBarcode_Scale_From_XdimDp", _ "long", $iSymbolID, "float", $fXDimMM, "float", $fDpmm, "str", $sFiletype)[0] EndFunc Func ZBarcode_XdimDp_From_Scale($iSymbolID, $fScale, $fXDimOrDpmm, $sFiletype = "") Return DllCall($g__ZintDLL, "float:cdecl", "ZBarcode_XdimDp_From_Scale", _ "long", $iSymbolID, "float", $fScale, "float", $fXDimOrDpmm, "str", $sFiletype)[0] EndFunc ; =================================================================== ; UTF-8 & ECI helpers ; =================================================================== Func ZBarcode_UTF8_To_ECI($iEci, $sSource, ByRef $sDest) Local $iLength = StringLen($sSource) Local $tSrc = DllStructCreate("struct;ubyte text[" & $iLength + 1 & "];endstruct") $tSrc.text = $sSource Local $tDest = DllStructCreate("ubyte[1024]") ; allocate buffer Local $pDestLen = DllStructCreate("int") Local $iResult = DllCall($g__ZintDLL, "long:cdecl", "ZBarcode_UTF8_To_ECI", "long", $iEci, "struct*", $tSrc, "long", $iLength + 1, "struct*", $tDest, "struct*", $pDestLen)[0] If $iResult Then Return SetError($iResult, 0, "") $sDest = BinaryToString(DllStructGetData($tDest, 1)) Return 1 EndFunc Func ZBarcode_Dest_Len_ECI($iEci, $sSource) Local $iLength = StringLen($sSource) Local $tSrc = DllStructCreate("struct;ubyte text[" & $iLength + 1 & "];endstruct") $tSrc.text = $sSource Local $pDestLen = DllStructCreate("int") Local $iResult = DllCall($g__ZintDLL, "long:cdecl", "ZBarcode_Dest_Len_ECI", "long", $iEci, "struct*", $tSrc, "long", $iLength + 1, "struct*", $pDestLen)[0] If $iResult Then Return SetError($iResult, 0, 0) Return DllStructGetData($pDestLen, 1) EndFunc ; =================================================================== ; Build info ; =================================================================== Func ZBarcode_NoPng() Return DllCall($g__ZintDLL, "long:cdecl", "ZBarcode_NoPng")[0] EndFunc Func ZBarcode_HaveGS1SyntaxEngine() Return DllCall($g__ZintDLL, "long:cdecl", "ZBarcode_HaveGS1SyntaxEngine")[0] EndFunc ; Return the version of Zint linked to Func ZBarcode_Version() Local $iResult = DllCall($g__ZintDLL, "long:cdecl", "ZBarcode_Version")[0] Local $a = StringRegExp((Mod(StringLen($iResult), 2) ? "0" : "") & $iResult, ".{2}", 3) If Not IsArray($a) Then Return SetError(1, 0, 0) Return StringFormat("%01i.%02i.%02i", $a[0], $a[1], $a[2]) EndFunc #EndRegion Example1.au3 expandcollapse popup#AutoIt3Wrapper_UseX64=y #include <GDIPlus.au3> #include "Zint.au3" Global Const $sTestFile = "out.png" ;default output name If FileExists($sTestFile) Then FileDelete($sTestFile) Global $pZB = ZBarcode_Create() If @error Then Exit MsgBox(16, "ERROR", "An error occured!" & @CRLF & "Error code = " & @error, 10) ConsoleWrite("Zint DLL version: " & ZBarcode_Version() & @CRLF) ConsoleWrite("PNG support: " & (ZBarcode_NoPng() ? "No" : "Yes") & @CRLF) Global $t_zint_symbol = DllStructCreate($tag_zint_symbol, $pZB) If @error Then MsgBox(16, "ERROR", "An error occured!" & @CRLF & "Error code = " & @error, 10) ZBarcode_Delete($pZB) Exit EndIf With $t_zint_symbol .symbology = $BARCODE_CODE128 .scale = 1 .option_1 = -1 .show_hrt = 1 .output_options = $SMALL_TEXT .outfile = $sTestFile EndWith ZBarcode_Encode_and_Print($pZB, "12340984576") Global $iError = @error ZBarcode_Delete($pZB) If FileExists($sTestFile) Then ShellExecute($sTestFile) Else MsgBox(16, "Error", "Code was not create. Error: " & $iError, 5) EndIf Example2.au3 #AutoIt3Wrapper_UseX64=n #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include "Zint.au3" Global Const $sTestFile = @ScriptDir & "\Barcode.png" Global $pZB = ZBarcode_Create() If @error Then Exit MsgBox(16, "ERROR", "An error occured!" & @CRLF & "Error code = " & @error, 10) Global $t_zint_symbol = DllStructCreate($tag_zint_symbol, $pZB) $t_zint_symbol.symbology = $BARCODE_QRCODE $t_zint_symbol.scale = 10 ZBarcode_Encode_and_Buffer($pZB, "Hello QR World ;-)") _GDIPlus_Startup() Global $stride = BitAND(($t_zint_symbol.bitmap_width * 3) + 3, BitNOT(3)) Global $iMemSize = $stride * $t_zint_symbol.bitmap_height Global $tPixel = DllStructCreate("ubyte rgb[" & $iMemSize & "];") Global $hBitmap = _GDIPlus_BitmapCreateFromScan0($t_zint_symbol.bitmap_width, $t_zint_symbol.bitmap_height, $GDIP_PXF24RGB, $stride, $tPixel) DllCall("msvcrt.dll", "ptr:cdecl", "memcpy", "struct*", $tPixel, "ptr", $t_zint_symbol.bitmap, "uint", $iMemSize) Global Const $hGUI = GUICreate("Test QR Code", $t_zint_symbol.bitmap_width, $t_zint_symbol.bitmap_height) GUISetState(@SW_SHOW) Global Const $hGfx = _GDIPlus_GraphicsCreateFromHWND($hGUI) _GDIPlus_GraphicsDrawImageRect($hGfx, $hBitmap, 0, 0, $t_zint_symbol.bitmap_width, $t_zint_symbol.bitmap_height) _GDIPlus_GraphicsDispose($hGfx) _GDIPlus_ImageDispose($hBitmap) _GDIPlus_Shutdown() ZBarcode_Delete($pZB) Do Until GUIGetMsg() = $GUI_EVENT_CLOSE Example3.au3 expandcollapse popup#AutoIt3Wrapper_UseX64=n #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include "Zint.au3" Global $pZB = ZBarcode_Create() If @error Then Exit MsgBox(16, "ERROR", "An error occured!" & @CRLF & "Error code = " & @error, 10) Global $t_zint_symbol = DllStructCreate($tag_zint_symbol, $pZB), $sText = "12340984576 ;-)" With $t_zint_symbol .symbology = $BARCODE_CODE128 .scale = 1 EndWith If Not ZBarcode_Encode_and_Buffer_Vector($pZB, $sText) Then Exit MsgBox(16, "ERROR", "Unable to encode!" & @CRLF & "Error code = " & @error, 10) Global $tVector = DllStructCreate($tag_zint_vector, $t_zint_symbol.vector) Global $tVector_Rect = DllStructCreate($tag_zint_vector_rect, $tVector.rectangles) ConsoleWrite($tVector.width & " x " & $tVector.height & @CRLF) _GDIPlus_Startup() Global $hBitmap = _GDIPlus_BitmapCreateFromScan0($tVector.width, $tVector.height, $GDIP_PXF24RGB), $hCanvas = _GDIPlus_ImageGetGraphicsContext($hBitmap), $hBrush = _GDIPlus_BrushCreateSolid() _GDIPlus_GraphicsClear($hCanvas, 0xFFFFFFFF) While $tVector_Rect.next _GDIPlus_BrushSetSolidColor($hBrush, BitAND($tVector_Rect.colour, 0xFF000000)) _GDIPlus_GraphicsFillRect($hCanvas, $tVector_Rect.x, $tVector_Rect.y, $tVector_Rect.width, $tVector_Rect.height, $hBrush) $tVector_Rect = DllStructCreate($tag_zint_vector_rect, $tVector_Rect.next) WEnd Global $tVector_String = DllStructCreate($tag_zint_vector_string, $tVector.strings) _GDIPlus_GraphicsDrawString($hCanvas, $sText, ($tVector_String.width - $tVector_String.length * $tVector_String.fsize * 0.55) / 2, $tVector.height - $tVector_String.fsize * 1.33333, "Arial", $tVector_String.fsize * 0.75, Default, 0xFF000000) Global Const $hGUI = GUICreate("Test Bar Code 128", $tVector.width, $tVector.height) GUISetState(@SW_SHOW) Global Const $hGfx = _GDIPlus_GraphicsCreateFromHWND($hGUI) _GDIPlus_GraphicsDrawImageRect($hGfx, $hBitmap, 0, 0, $tVector.width, $tVector.height) _GDIPlus_GraphicsDispose($hCanvas) _GDIPlus_GraphicsDispose($hGfx) _GDIPlus_ImageDispose($hBitmap) _GDIPlus_BrushDispose($hBrush) _GDIPlus_Shutdown() ZBarcode_Delete($pZB) Do Until GUIGetMsg() = $GUI_EVENT_CLOSE Example4.au3 expandcollapse popup#AutoIt3Wrapper_UseX64=y #include "Zint.au3" ; =================================================================== ; Zint AutoIt Demo Test ; =================================================================== ; ------------------------------------------------------------------- ; Step 1: Create a symbol ; ------------------------------------------------------------------- ConsoleWrite("Step 1: Create a symbol" & @CRLF) Global $pSymbol = ZBarcode_Create() If @error Then MsgBox(16, "Error", "Failed to create symbol") Exit EndIf ConsoleWrite("Symbol created: " & $pSymbol & @CRLF) ConsoleWrite(@CRLF) ; ------------------------------------------------------------------- ; Step 2: Encode a simple string ; ------------------------------------------------------------------- ConsoleWrite("Step 2: Encode a simple string" & @CRLF) Global $sData = "HELLO123" If ZBarcode_Encode($pSymbol, $sData) Then ConsoleWrite("Encoding succeeded" & @CRLF) Else ConsoleWrite("Encoding failed, error: " & @error & @CRLF) EndIf ConsoleWrite(@CRLF) ; ------------------------------------------------------------------- ; Step 3: Output to raster buffer ; ------------------------------------------------------------------- ConsoleWrite("Step 3: Output to raster buffer" & @CRLF) If ZBarcode_Buffer($pSymbol) Then ConsoleWrite("Raster buffer generated successfully" & @CRLF) Else ConsoleWrite("Raster buffer generation failed, error: " & @error & @CRLF) EndIf ConsoleWrite(@CRLF) ; ------------------------------------------------------------------- ; Step 4: Output to vector buffer ; ------------------------------------------------------------------- ConsoleWrite("Step 4: Output to vector buffer" & @CRLF) If ZBarcode_Buffer_Vector($pSymbol) Then ConsoleWrite("Vector buffer generated successfully" & @CRLF) Else ConsoleWrite("Vector buffer generation failed, error: " & @error & @CRLF) EndIf ConsoleWrite(@CRLF) ; ------------------------------------------------------------------- ; Step 5: Print to file (just test call, file may not exist) ; ------------------------------------------------------------------- ConsoleWrite("Step 5: Print to file" & @CRLF) Global $t_zint_symbol = DllStructCreate($tag_zint_symbol, $pSymbol) $t_zint_symbol.symbology = $BARCODE_CODE128 $t_zint_symbol.input_mode = $DATA_MODE $t_zint_symbol.height = 50 $t_zint_symbol.scale = 1 $t_zint_symbol.option_1 = 0 $t_zint_symbol.option_2 = 0 $t_zint_symbol.option_3 = 0 $t_zint_symbol.show_hrt = 1 If ZBarcode_Print(DllStructGetPtr($t_zint_symbol)) Then ConsoleWrite("Print function call succeeded" & @CRLF) Else ConsoleWrite("Print failed, error: " & @error & @CRLF) EndIf ConsoleWrite(@CRLF) ; ------------------------------------------------------------------- ; Step 6: Get barcode info ; ------------------------------------------------------------------- ConsoleWrite("Step 6: Get barcode info" & @CRLF) ConsoleWrite("Valid ID for CODE128: " & ZBarcode_ValidID(20) & @CRLF) ConsoleWrite("Barcode name for CODE128: " & ZBarcode_BarcodeName(20) & @CRLF) ConsoleWrite("Default X-dim for CODE128: " & ZBarcode_Default_Xdim(20) & " mm" & @CRLF) ConsoleWrite(@CRLF) ; ------------------------------------------------------------------- ; Step 7: UTF-8 to ECI conversion test ; ------------------------------------------------------------------- ConsoleWrite("Step 7: UTF-8 to ECI conversion test" & @CRLF) Global $sDest If ZBarcode_UTF8_To_ECI(3, "HELLO", $sDest) Then ConsoleWrite("UTF-8 to ECI conversion succeeded: " & $sDest & @CRLF) Else ConsoleWrite("UTF-8 to ECI conversion failed, error: " & @error & @CRLF) EndIf ConsoleWrite(@CRLF) ConsoleWrite(@CRLF) ; ------------------------------------------------------------------- ; Step 8: Check Zint build info ; ------------------------------------------------------------------- ConsoleWrite("Step 8: Check Zint build info" & @CRLF) ConsoleWrite("Zint No PNG support: " & ZBarcode_NoPng() & @CRLF) ConsoleWrite("Zint GS1 support: " & ZBarcode_HaveGS1SyntaxEngine() & @CRLF) ConsoleWrite("Zint Version: " & ZBarcode_Version() & @CRLF) ConsoleWrite(@CRLF) ; ------------------------------------------------------------------- ; Step 9: Clear, reset and delete symbol ; ------------------------------------------------------------------- ConsoleWrite("Step 9: Clear, reset and delete symbol" & @CRLF) ZBarcode_Clear($pSymbol) ConsoleWrite("Symbol cleared" & @CRLF) ZBarcode_Reset($pSymbol) ConsoleWrite("Symbol reset" & @CRLF) ZBarcode_Delete($pSymbol) ConsoleWrite("Symbol deleted" & @CRLF) ConsoleWrite(@CRLF) MsgBox(64, "Demo Complete", "Zint AutoIt demo test finished successfully.") Example5.au3 expandcollapse popup#AutoIt3Wrapper_UseX64=y #include "Zint.au3" ; Zint Symbol erstellen Global $pZB = ZBarcode_Create() If @error Then Exit MsgBox(16, "ERROR", "An error occured!" & @CRLF & "Error code = " & @error, 10) ; Configure Zint Symbol structure Global $t_zint_symbol = DllStructCreate($tag_zint_symbol, $pZB) With $t_zint_symbol .symbology = $BARCODE_AZTEC .input_mode = $UNICODE_MODE .scale = 10 .outfile = @ScriptDir & "\segtest.png" EndWith If FileExists($t_zint_symbol.outfile) Then FileDelete($t_zint_symbol.outfile) Global $tagSeg = "ptr source; int length; int eci" ; --- Create continuous array --- Global $iSize = (@AutoItX64 ? 16 : 12) ;size of $tagSeg Global $tContinuousArray = DllStructCreate("byte[" & $iSize * 3 & "]") ; --- Create individual zint_seg structures --- Global $tSeg1 = DllStructCreate($tagSeg, DllStructGetPtr($tContinuousArray)) Global $tSeg2 = DllStructCreate($tagSeg, DllStructGetPtr($tContinuousArray) + $iSize) Global $tSeg3 = DllStructCreate($tagSeg, DllStructGetPtr($tContinuousArray) + 2 * $iSize) ; --- Create the text data --- Global $sText1 = "Κείμενο" ; Greek Global $sText2 = "Текст" ; Cyrillic Global $sText3 = "文章" ; Chinese ; Convert to UTF-8 (or use direct string pointers if Zint.au3 supports it) Global $tText1 = DllStructCreate("char t[256]") Global $tText2 = DllStructCreate("char t[256]") Global $tText3 = DllStructCreate("char t[256]") $tText1.t = $sText1 $tText2.t = $sText2 $tText3.t = $sText3 ; --- Fill the segment structures --- $tSeg1.source = DllStructGetPtr($tText1) $tSeg1.length = 0 ; 0 = NUL-terminated $tSeg1.eci = 9 ; Greek ECI $tSeg2.source = DllStructGetPtr($tText2) $tSeg2.length = 0 $tSeg2.eci = 7 ; Cyrillic ECI $tSeg3.source = DllStructGetPtr($tText3) $tSeg3.length = 0 $tSeg3.eci = 20 ; Chinese ECI Global $iError = 0 ; --- Call ZBarcode_Encode_Segs --- If Not ZBarcode_Encode_Segs($pZB, DllStructGetPtr($tContinuousArray), 3) Then $iError = @error MsgBox(16, "ERROR", "ZBarcode_Encode_Segs returned error: " & $iError, 10) EndIf ZBarcode_Print($pZB, 0) If Not $iError Then ShellExecute($t_zint_symbol.outfile) ZBarcode_Delete($pZB) Please test and reply. Feel free to post examples here! Edited September 16 by UEZ UDF Update Norm73, KaFu, philpw99 and 9 others 8 4 Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
kurtykurtyboy Posted July 4, 2022 Posted July 4, 2022 Very nice! I had never heard of zint. I tried a long time ago to do something like this but gave up. I still need to research what is possible with this. But is there a way to generate the barcode without the text underneath?
UEZ Posted July 4, 2022 Author Posted July 4, 2022 49 minutes ago, kurtykurtyboy said: Very nice! I had never heard of zint. I tried a long time ago to do something like this but gave up. I still need to research what is possible with this. But is there a way to generate the barcode without the text underneath? Thanks for your feedback. Yes, you can add $t_zint_symbol.show_hrt = 0 to hide text. $t_zint_symbol.scale = 2 $t_zint_symbol.show_hrt = 0 ZBarcode_Encode_and_Print($pZB, "0123456789ABCDEF") I need to check out how to create other barcodes because it doesn't work by just selecting them... argumentum 1 Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
Resiak1811 Posted July 16, 2022 Posted July 16, 2022 Hello, (sorry for my english.. I'm french) look interesting.. specially with all the included barcode but I don't know if its me but doesn't seem to work.. I'm with SciTE Version 3.5.4 (AutoIt v3.3.14.5).. I copied/pasted the text into ZintDll.au3 and in Zint.au3 ... The 1st time I run it, it create the Zint.dll but I have this error : "D:\test\Zint.au3" (267) : ==> Subscript used on non-accessible variable.: Local $hPtr = DllCall($g__ZintDLL, "ptr:cdecl", "ZBarcode_Create")[0] Local $hPtr = DllCall($g__ZintDLL, "ptr:cdecl", "ZBarcode_Create")^ ERROR any idea ?
Gianni Posted July 16, 2022 Posted July 16, 2022 @Resiak1811, maybe the DLL is not created correctly, ... or worse still, it gets corrupted after it is created ... Using the technique presented by the great @trancexx described at this link: https://www.autoitscript.com/forum/topic/108969-subrogation , I modified the Zint.au3 file so that instead of creating and saving the DLL on disk, it creates it in memory and uses it directly from memory without saving it to disk. Can you rename the original Zint.au3 file to something different and save this modified version in its place and tell if that works? Zint.au3 expandcollapse popup;Coded by UEZ ;v0.50 build 2022-06-30 beta ;32 bit (x86) only! ;IMPORTANT: You are not allowed to sell this code or just parts of it in a commercial project or modify it and distribute it with a different name! ; Distributing copies of the program in compiled format (exe) must be free of any fee! #include-once #include <WinAPI.au3> #include <Memory.au3> #include "ZintDll.au3" ; Global $g__ZintDLL = @ScriptDir & "\Zint.dll" Global $g__ZintDLL = DllFromMemory(_Zint_dll(False)) #Region Constances Const $BARCODE_CODE11 = 1 ; Code 11 Const $BARCODE_C25STANDARD = 2 ; 2 of 5 Standard (Matrix) Const $BARCODE_C25MATRIX = 2 ; Legacy Const $BARCODE_C25INTER = 3 ; 2 of 5 Interleaved Const $BARCODE_C25IATA = 4 ; 2 of 5 IATA Const $BARCODE_C25LOGIC = 6 ; 2 of 5 Data Logic Const $BARCODE_C25IND = 7 ; 2 of 5 Industrial Const $BARCODE_CODE39 = 8 ; Code 39 Const $BARCODE_EXCODE39 = 9 ; Extended Code 39 Const $BARCODE_EANX = 13 ; EAN (European Article Number) Const $BARCODE_EANX_CHK = 14 ; EAN + Check Digit Const $BARCODE_GS1_128 = 16 ; GS1-128 Const $BARCODE_EAN128 = 16 ; Legacy Const $BARCODE_CODABAR = 18 ; Codabar Const $BARCODE_CODE128 = 20 ; Code 128 Const $BARCODE_DPLEIT = 21 ; Deutsche Post Leitcode Const $BARCODE_DPIDENT = 22 ; Deutsche Post Identcode Const $BARCODE_CODE16K = 23 ; Code 16k Const $BARCODE_CODE49 = 24 ; Code 49 Const $BARCODE_CODE93 = 25 ; Code 93 Const $BARCODE_FLAT = 28 ; Flattermarken Const $BARCODE_DBAR_OMN = 29 ; GS1 DataBar Omnidirectional Const $BARCODE_RSS14 = 29 ; Legacy Const $BARCODE_DBAR_LTD = 30 ; GS1 DataBar Limited Const $BARCODE_RSS_LTD = 30 ; Legacy Const $BARCODE_DBAR_EXP = 31 ; GS1 DataBar Expanded Const $BARCODE_RSS_EXP = 31 ; Legacy Const $BARCODE_TELEPEN = 32 ; Telepen Alpha Const $BARCODE_UPCA = 34 ; UPC-A Const $BARCODE_UPCA_CHK = 35 ; UPC-A + Check Digit Const $BARCODE_UPCE = 37 ; UPC-E Const $BARCODE_UPCE_CHK = 38 ; UPC-E + Check Digit Const $BARCODE_POSTNET = 40 ; USPS (U.S. Postal Service) POSTNET Const $BARCODE_MSI_PLESSEY = 47 ; MSI Plessey Const $BARCODE_FIM = 49 ; Facing Identification Mark Const $BARCODE_LOGMARS = 50 ; LOGMARS Const $BARCODE_PHARMA = 51 ; Pharmacode One-Track Const $BARCODE_PZN = 52 ; Pharmazentralnummer Const $BARCODE_PHARMA_TWO = 53 ; Pharmacode Two-Track Const $BARCODE_PDF417 = 55 ; PDF417 Const $BARCODE_PDF417COMP = 56 ; Compact PDF417 (Truncated PDF417) Const $BARCODE_PDF417TRUNC = 56 ; Legacy Const $BARCODE_MAXICODE = 57 ; MaxiCode Const $BARCODE_QRCODE = 58 ; QR Code Const $BARCODE_CODE128B = 60 ; Code 128 (Subset B) Const $BARCODE_AUSPOST = 63 ; Australia Post Standard Customer Const $BARCODE_AUSREPLY = 66 ; Australia Post Reply Paid Const $BARCODE_AUSROUTE = 67 ; Australia Post Routing Const $BARCODE_AUSREDIRECT = 68 ; Australia Post Redirection Const $BARCODE_ISBNX = 69 ; ISBN Const $BARCODE_RM4SCC = 70 ; Royal Mail 4 State Const $BARCODE_DATAMATRIX = 71 ; Data Matrix (ECC200) Const $BARCODE_EAN14 = 72 ; EAN-14 Const $BARCODE_VIN = 73 ; Vehicle Identification Number Const $BARCODE_CODABLOCKF = 74 ; Codablock-F Const $BARCODE_NVE18 = 75 ; NVE-18 (SSCC-18) Const $BARCODE_JAPANPOST = 76 ; Japanese Postal Code Const $BARCODE_KOREAPOST = 77 ; Korea Post Const $BARCODE_DBAR_STK = 79 ; GS1 DataBar Stacked Const $BARCODE_RSS14STACK = 79 ; Legacy Const $BARCODE_DBAR_OMNSTK = 80 ; GS1 DataBar Stacked Omnidirectional Const $BARCODE_RSS14STACK_OMNI = 80 ; Legacy Const $BARCODE_DBAR_EXPSTK = 81 ; GS1 DataBar Expanded Stacked Const $BARCODE_RSS_EXPSTACK = 81 ; Legacy Const $BARCODE_PLANET = 82 ; USPS PLANET Const $BARCODE_MICROPDF417 = 84 ; MicroPDF417 Const $BARCODE_USPS_IMAIL = 85 ; USPS Intelligent Mail (OneCode) Const $BARCODE_ONECODE = 85 ; Legacy Const $BARCODE_PLESSEY = 86 ; UK Plessey ; Tbarcode 8 codes Const $BARCODE_TELEPEN_NUM = 87 ; Telepen Numeric Const $BARCODE_ITF14 = 89 ; ITF-14 Const $BARCODE_KIX = 90 ; Dutch Post KIX Code Const $BARCODE_AZTEC = 92 ; Aztec Code Const $BARCODE_DAFT = 93 ; DAFT Code Const $BARCODE_DPD = 96 ; DPD Code Const $BARCODE_MICROQR = 97 ; Micro QR Code ; Tbarcode 9 codes Const $BARCODE_HIBC_128 = 98 ; HIBC (Health Industry $BARCODE) Code 128 Const $BARCODE_HIBC_39 = 99 ; HIBC Code 39 Const $BARCODE_HIBC_DM = 102 ; HIBC Data Matrix Const $BARCODE_HIBC_QR = 104 ; HIBC QR Code Const $BARCODE_HIBC_PDF = 106 ; HIBC PDF417 Const $BARCODE_HIBC_MICPDF = 108 ; HIBC MicroPDF417 Const $BARCODE_HIBC_BLOCKF = 110 ; HIBC Codablock-F Const $BARCODE_HIBC_AZTEC = 112 ; HIBC Aztec Code ; Tbarcode 10 codes Const $BARCODE_DOTCODE = 115 ; DotCode Const $BARCODE_HANXIN = 116 ; Han Xin (Chinese Sensible) Code ; Tbarcode 11 codes Const $BARCODE_MAILMARK = 121 ; Royal Mail 4-state Mailmark ; $ZINT specific Const $BARCODE_AZRUNE = 128 ; Aztec Runes Const $BARCODE_CODE32 = 129 ; Code 32 Const $BARCODE_EANX_CC = 130 ; EAN Composite Const $BARCODE_GS1_128_CC = 131 ; GS1-128 Composite Const $BARCODE_EAN128_CC = 131 ; Legacy Const $BARCODE_DBAR_OMN_CC = 132 ; GS1 DataBar Omnidirectional Composite Const $BARCODE_RSS14_CC = 132 ; Legacy Const $BARCODE_DBAR_LTD_CC = 133 ; GS1 DataBar Limited Composite Const $BARCODE_RSS_LTD_CC = 133 ; Legacy Const $BARCODE_DBAR_EXP_CC = 134 ; GS1 DataBar Expanded Composite Const $BARCODE_RSS_EXP_CC = 134 ; Legacy Const $BARCODE_UPCA_CC = 135 ; UPC-A Composite Const $BARCODE_UPCE_CC = 136 ; UPC-E Composite Const $BARCODE_DBAR_STK_CC = 137 ; GS1 DataBar Stacked Composite Const $BARCODE_RSS14STACK_CC = 137 ; Legacy Const $BARCODE_DBAR_OMNSTK_CC = 138 ; GS1 DataBar Stacked Omnidirectional Composite Const $BARCODE_RSS14_OMNI_CC = 138 ; Legacy Const $BARCODE_DBAR_EXPSTK_CC = 139 ; GS1 DataBar Expanded Stacked Composite Const $BARCODE_RSS_EXPSTACK_CC = 139 ; Legacy Const $BARCODE_CHANNEL = 140 ; Channel Code Const $BARCODE_CODEONE = 141 ; Code One Const $BARCODE_GRIDMATRIX = 142 ; Grid Matrix Const $BARCODE_UPNQR = 143 ; UPNQR (Univerzalnega Placilnega Naloga QR) Const $BARCODE_ULTRA = 144 ; Ultracode Const $BARCODE_RMQR = 145 ; Rectangular Micro QR Code (rMQR) Const $BARCODE_LAST = 145 ; Max $BARCODE number marker, not $BARCODE ; Output options (`symbol->output_options`) Const $BARCODE_NO_ASCII = 0x0001 ; Legacy (no-op) Const $BARCODE_BIND = 0x0002 ; Boundary bars above & below the symbol and between stacked symbols Const $BARCODE_BOX = 0x0004 ; Box around symbol Const $BARCODE_STDOUT = 0x0008 ; Output to stdout Const $READER_INIT = 0x0010 ; Reader Initialisation (Programming) Const $SMALL_TEXT = 0x0020 ; Use smaller font Const $BOLD_TEXT = 0x0040 ; Use bold font Const $CMYK_COLOUR = 0x0080 ; CMYK colour space (Encapsulated PostScript and TIF) Const $BARCODE_DOTTY_MODE = 0x0100 ; Plot a matrix symbol using dots rather than squares Const $GS1_GS_SEPARATOR = 0x0200 ; Use GS instead of FNC1 as GS1 separator (Data Matrix) Const $OUT_BUFFER_INTERMEDIATE = 0x0400 ; Return ASCII values in bitmap buffer (OUT_BUFFER only) Const $BARCODE_QUIET_ZONES = 0x0800 ; Add compliant quiet zones (additional to any specified whitespace) ; Note: CODE16K, CODE49, CODABLOCKF, ITF14, EAN/UPC have default quiet zones Const $BARCODE_NO_QUIET_ZONES = 0x1000 ; Disable quiet zones, notably those with defaults as listed above Const $COMPLIANT_HEIGHT = 0x2000 ; Warn if height not compliant and use standard height (if any) as default ; Input data types (`symbol->input_mode`) Const $DATA_MODE = 0 ; Binary Const $UNICODE_MODE = 1 ; UTF-8 Const $GS1_MODE = 2 ; GS1 ; The following may be OR-ed with above Const $ESCAPE_MODE = 0x0008 ; Process escape sequences Const $GS1PARENS_MODE = 0x0010 ; Process parentheses as GS1 AI delimiters (instead of square brackets) Const $GS1NOCHECK_MODE = 0x0020 ; Do not check validity of GS1 data (except that printable ASCII only) Const $HEIGHTPERROW_MODE = 0x0040 ; Interpret `height` as per-row rather than as overall height Const $FAST_MODE = 0x0080 ; Use faster if less optimal encodation for symbologies that support it ; Note: only DATAMATRIX currently ; Data Matrix specific options (`symbol->option_3`) Const $DM_SQUARE = 100 ; Only consider square versions on automatic symbol size selection Const $DM_DMRE = 101 ; Consider DMRE versions on automatic symbol size selection ; QR, Han Xin, Grid Matrix specific options (`symbol->option_3`) Const $ZINT_FULL_MULTIBYTE = 200 ; Enable Kanji/Hanzi compression for Latin-1 & binary data ; Ultracode specific option (`symbol->option_3`) Const $ULTRA_COMPRESSION = 128 ; Enable Ultracode compression (experimental) ; Warning and error conditions (API return values) Const $ZINT_WARN_INVALID_OPTION = 2 ; Invalid option given but overridden by $ZINT Const $ZINT_WARN_USES_ECI = 3 ; Automatic ECI inserted by $ZINT Const $ZINT_WARN_NONCOMPLIANT = 4 ; Symbol created not compliant with standards Const $ZINT_ERROR = 5 ; Warn/error marker, not returned Const $ZINT_ERROR_TOO_LONG = 5 ; Input data wrong length Const $ZINT_ERROR_INVALID_DATA = 6 ; Input data incorrect Const $ZINT_ERROR_INVALID_CHECK = 7 ; Input check digit incorrect Const $ZINT_ERROR_INVALID_OPTION = 8 ; Incorrect option given Const $ZINT_ERROR_ENCODING_PROBLEM = 9 ; Internal error (should not happen) Const $ZINT_ERROR_FILE_ACCESS = 10 ; Error opening output file Const $ZINT_ERROR_MEMORY = 11 ; Memory allocation (malloc) failure Const $ZINT_ERROR_FILE_WRITE = 12 ; Error writing to output file Const $ZINT_ERROR_USES_ECI = 13 ; Error counterpart of warning if WARN_FAIL_ALL set (see below) Const $ZINT_ERROR_NONCOMPLIANT = 14 ; Error counterpart of warning if WARN_FAIL_ALL set ; Warning warn (`symbol->warn_level`) Const $WARN_DEFAULT = 0 ; Default behaviour Const $WARN_FAIL_ALL = 2 ; Treat warning as error ; Capability flags (ZBarcode_Cap() `cap_flag`) Const $ZINT_CAP_HRT = 0x0001 ; Prints Human Readable Text? Const $ZINT_CAP_STACKABLE = 0x0002 ; Is stackable? Const $ZINT_CAP_EXTENDABLE = 0x0004 ; Is extendable with add-on data? (Is EAN/UPC?) Const $ZINT_CAP_COMPOSITE = 0x0008 ; Can have composite data? Const $ZINT_CAP_ECI = 0x0010 ; Supports Extended Channel Interpretations? Const $ZINT_CAP_GS1 = 0x0020 ; Supports GS1 data? Const $ZINT_CAP_DOTTY = 0x0040 ; Can be output as dots? Const $ZINT_CAP_QUIET_ZONES = 0x0080 ; Has default quiet zones? Const $ZINT_CAP_FIXED_RATIO = 0x0100 ; Has fixed width-to-height (aspect) ratio? Const $ZINT_CAP_READER_INIT = 0x0200 ; Supports Reader Initialisation? Const $ZINT_CAP_FULL_MULTIBYTE = 0x0400 ; Supports full-multibyte option? Const $ZINT_CAP_MASK = 0x0800 ; Is mask selectable? Const $ZINT_CAP_STRUCTAPP = 0x1000 ; Supports Structured Append? Const $ZINT_CAP_COMPLIANT_HEIGHT = 0x2000 ; Has compliant height? ; The largest amount of data that can be encoded is 4350 4-byte UTF-8 chars in Han Xin Code Const $ZINT_MAX_DATA_LEN = 17400 ; Maximum number of segments allowed for (`seg_count`) Const $ZINT_MAX_SEG_COUNT = 256 #EndRegion Global Const $tag_zint_vector_rect = "struct;float x;float y;float height;float width;long colour;ptr next;endstruct" Global Const $tag_zint_vector_hexagon = "struct;float x;float y;float diameter;long rotation;ptr next;endstruct" Global Const $tag_zint_vector_string = "struct;float x;float y;float fsize;float width;long length;long rotation;long halign;ptr text;ptr next;endstruct" Global Const $tag_zint_vector_circlezint_vector_circle = "struct;float x;float y;float diameter;float width;long colour;ptr next;endstruct" Global Const $tag_zint_vector = "struct;float width;float heigth;ptr rectangles;ptr hexagons;ptr strings;ptr circles;endstruct" Global Const $tag_zint_seg = "struct;ptr source;long length;long eci;endstruct" Global Const $tag_zint_structapp = "struct;long index;long count;char id[32];endstruct" Global Const $tag_zint_symbol = "struct;long symbology;" & _ "float height;" & _ "float scale;" & _ "long whitespace_width;" & _ "long whitespace_height;" & _ "long border_width;" & _ "long output_options;" & _ "char fgcolour[10];" & _ "char bgcolour[10];" & _ "ptr fgcolor;" & _ "ptr bgcolor;" & _ "char outfile[256];" & _ "char primary[128];" & _ "long option_1;" & _ "long option_2;" & _ "long option_3;" & _ "long show_hrt;" & _ "long fontsize;" & _ "long input_mode;" & _ "long eci;" & _ "float dot_size;" & _ "float guard_descent;" & _ "long index;" & _ "long count;" & _ "char id[32];" & _ "long warn_level;" & _ "long debug;" & _ "char text[128];" & _ "long rows;" & _ "long width;" & _ "ubyte encoded_data[28800];" & _ "float row_height[200];" & _ "char errtxt[100];" & _ "ptr bitmap;" & _ "long bitmap_width;" & _ "long bitmap_height;" & _ "ptr alphamap;" & _ "ulong bitmap_byte_length;" & _ "ptr vector;endstruct" Func ZBarcode_Create() ; If Not FileExists($g__ZintDLL) Then _Zint_dll(True) Local $hPtr = DllCall($g__ZintDLL, "ptr:cdecl", "ZBarcode_Create")[0] If $hPtr = 0 Then Return SetError(1, 0, 0) Return $hPtr EndFunc Func ZBarcode_Delete($pSymbol) If IsPtr($pSymbol) And $pSymbol <> 0 Then DllCall($g__ZintDLL, "none:cdecl", "ZBarcode_Delete", "ptr", $pSymbol) Return 1 EndIf Return SetError(1, 0, 0) EndFunc Func ZBarcode_Encode($pSymbol, $sInput) Local $iLength = StringLen($sInput), $tInput = DllStructCreate("struct;ubyte text[" & $iLength + 1 & "];endstruct") $tInput.text = $sInput Local $iResult = DllCall($g__ZintDLL, "long:cdecl", "ZBarcode_Encode", "ptr", $pSymbol, "struct*", $tInput, "long", $iLength + 1)[0] If $iResult Then Return SetError($iResult, 0, 0) Return 1 EndFunc Func ZBarcode_Buffer($pSymbol, $iAngle = 0) Local $iResult = DllCall($g__ZintDLL, "long:cdecl", "ZBarcode_Buffer", "ptr", $pSymbol, "long", $iAngle)[0] If $iResult Then Return SetError($iResult, 0, 0) Return 1 EndFunc Func ZBarcode_Buffer_Vector($pSymbol, $iAngle = 0) Local $iResult = DllCall($g__ZintDLL, "long:cdecl", "ZBarcode_Buffer_Vector", "ptr", $pSymbol, "long", $iAngle)[0] If $iResult Then Return SetError($iResult, 0, 0) Return 1 EndFunc Func ZBarcode_Encode_and_Buffer($pSymbol, $sInput, $iRotate = 0) Local $iLength = StringLen($sInput), $tInput = DllStructCreate("struct;ubyte text[" & $iLength + 1 & "];endstruct") $tInput.text = $sInput Local $iResult = DllCall($g__ZintDLL, "long:cdecl", "ZBarcode_Encode_and_Buffer", "ptr", $pSymbol, "struct*", $tInput, "long", $iLength + 1, "long", $iRotate)[0] If $iResult Then Return SetError($iResult, 0, 0) Return 1 EndFunc Func ZBarcode_Encode_and_Buffer_Vector($pSymbol, $sInput, $iRotate = 0) Local $iLength = StringLen($sInput), $tInput = DllStructCreate("struct;ubyte text[" & $iLength + 1 & "];endstruct") $tInput.text = $sInput Local $iResult = DllCall($g__ZintDLL, "long:cdecl", "ZBarcode_Encode_and_Buffer_Vector", "ptr", $pSymbol, "struct*", $tInput, "long", $iLength + 1, "long", $iRotate)[0] If $iResult Then Return SetError($iResult, 0, 0) Return 1 EndFunc Func ZBarcode_Encode_and_Print($pSymbol, $sInput, $iRotate = 0) Local $iLength = StringLen($sInput), $tInput = DllStructCreate("struct;ubyte text[" & $iLength + 1 & "];endstruct") $tInput.text = $sInput Local $iResult = DllCall($g__ZintDLL, "long:cdecl", "ZBarcode_Encode_and_Print", "ptr", $pSymbol, "struct*", $tInput, "long", $iLength + 1, "long", $iRotate)[0] If $iResult Then Return SetError($iResult, 0, 0) Return 1 EndFunc ; the stuff below is from the great TRANCEXX ; https://www.autoitscript.com/forum/topic/108969-subrogation/ ; SUBROGATION FUNCTIONS ; ^^ If you want them in your script then just copy/paste what's below this line. ; If you think the code is worth something my PayPal address is: trancexx at yahoo dot com ; Thank you for the shiny stuff :kiss: ;********************************************************************************************; Func DllFromMemory($bBinaryImage, $sSubrogor = "explorer.exe") ; Make structure out of binary data that was passed Local $tBinary = DllStructCreate("byte[" & BinaryLen($bBinaryImage) & "]") DllStructSetData($tBinary, 1, $bBinaryImage) ; fill the structure ; Get pointer to it Local $pPointer = DllStructGetPtr($tBinary) ; Start processing passed binary data. 'Reading' PE format follows. Local $tIMAGE_DOS_HEADER = DllStructCreate("char Magic[2];" & _ "word BytesOnLastPage;" & _ "word Pages;" & _ "word Relocations;" & _ "word SizeofHeader;" & _ "word MinimumExtra;" & _ "word MaximumExtra;" & _ "word SS;" & _ "word SP;" & _ "word Checksum;" & _ "word IP;" & _ "word CS;" & _ "word Relocation;" & _ "word Overlay;" & _ "char Reserved[8];" & _ "word OEMIdentifier;" & _ "word OEMInformation;" & _ "char Reserved2[20];" & _ "dword AddressOfNewExeHeader", _ $pPointer) ; Move pointer $pPointer += DllStructGetData($tIMAGE_DOS_HEADER, "AddressOfNewExeHeader") ; move to PE file header Local $sMagic = DllStructGetData($tIMAGE_DOS_HEADER, "Magic") ; Check if it's valid format If Not ($sMagic == "MZ") Then Return SetError(1, 0, 0) ; MS-DOS header missing. Btw 'MZ' are the initials of Mark Zbikowski in case you didn't know. EndIf Local $tIMAGE_NT_SIGNATURE = DllStructCreate("dword Signature", $pPointer) ; Move pointer $pPointer += 4 ; size of $tIMAGE_NT_SIGNATURE structure ; Check signature If DllStructGetData($tIMAGE_NT_SIGNATURE, "Signature") <> 17744 Then ; IMAGE_NT_SIGNATURE Return SetError(2, 0, 0) ; wrong signature. For PE image should be "PE\0\0" or 17744 dword. EndIf ; In place of IMAGE_FILE_HEADER structure Local $tIMAGE_FILE_HEADER = DllStructCreate("word Machine;" & _ "word NumberOfSections;" & _ "dword TimeDateStamp;" & _ "dword PointerToSymbolTable;" & _ "dword NumberOfSymbols;" & _ "word SizeOfOptionalHeader;" & _ "word Characteristics", _ $pPointer) ; Get number of sections Local $iNumberOfSections = DllStructGetData($tIMAGE_FILE_HEADER, "NumberOfSections") ; Move pointer $pPointer += 20 ; size of $tIMAGE_FILE_HEADER structure ; Determine the type Local $tMagic = DllStructCreate("word Magic;", $pPointer) Local $iMagic = DllStructGetData($tMagic, 1) Local $tIMAGE_OPTIONAL_HEADER If $iMagic = 267 Then ; x86 version If @AutoItX64 Then Return SetError(3, 0, 0) ; uncompatible versions $tIMAGE_OPTIONAL_HEADER = DllStructCreate("word Magic;" & _ "byte MajorLinkerVersion;" & _ "byte MinorLinkerVersion;" & _ "dword SizeOfCode;" & _ "dword SizeOfInitializedData;" & _ "dword SizeOfUninitializedData;" & _ "dword AddressOfEntryPoint;" & _ "dword BaseOfCode;" & _ "dword BaseOfData;" & _ "dword ImageBase;" & _ "dword SectionAlignment;" & _ "dword FileAlignment;" & _ "word MajorOperatingSystemVersion;" & _ "word MinorOperatingSystemVersion;" & _ "word MajorImageVersion;" & _ "word MinorImageVersion;" & _ "word MajorSubsystemVersion;" & _ "word MinorSubsystemVersion;" & _ "dword Win32VersionValue;" & _ "dword SizeOfImage;" & _ "dword SizeOfHeaders;" & _ "dword CheckSum;" & _ "word Subsystem;" & _ "word DllCharacteristics;" & _ "dword SizeOfStackReserve;" & _ "dword SizeOfStackCommit;" & _ "dword SizeOfHeapReserve;" & _ "dword SizeOfHeapCommit;" & _ "dword LoaderFlags;" & _ "dword NumberOfRvaAndSizes", _ $pPointer) ; Move pointer $pPointer += 96 ; size of $tIMAGE_OPTIONAL_HEADER ElseIf $iMagic = 523 Then ; x64 version If Not @AutoItX64 Then Return SetError(3, 0, 0) ; uncompatible versions $tIMAGE_OPTIONAL_HEADER = DllStructCreate("word Magic;" & _ "byte MajorLinkerVersion;" & _ "byte MinorLinkerVersion;" & _ "dword SizeOfCode;" & _ "dword SizeOfInitializedData;" & _ "dword SizeOfUninitializedData;" & _ "dword AddressOfEntryPoint;" & _ "dword BaseOfCode;" & _ "uint64 ImageBase;" & _ "dword SectionAlignment;" & _ "dword FileAlignment;" & _ "word MajorOperatingSystemVersion;" & _ "word MinorOperatingSystemVersion;" & _ "word MajorImageVersion;" & _ "word MinorImageVersion;" & _ "word MajorSubsystemVersion;" & _ "word MinorSubsystemVersion;" & _ "dword Win32VersionValue;" & _ "dword SizeOfImage;" & _ "dword SizeOfHeaders;" & _ "dword CheckSum;" & _ "word Subsystem;" & _ "word DllCharacteristics;" & _ "uint64 SizeOfStackReserve;" & _ "uint64 SizeOfStackCommit;" & _ "uint64 SizeOfHeapReserve;" & _ "uint64 SizeOfHeapCommit;" & _ "dword LoaderFlags;" & _ "dword NumberOfRvaAndSizes", _ $pPointer) ; Move pointer $pPointer += 112 ; size of $tIMAGE_OPTIONAL_HEADER Else Return SetError(3, 0, 0) ; uncompatible versions EndIf ; Extract data Local $iSizeOfImage = DllStructGetData($tIMAGE_OPTIONAL_HEADER, "SizeOfImage") ; if loaded binary image would start executing at this address Local $iEntryPoint = DllStructGetData($tIMAGE_OPTIONAL_HEADER, "AddressOfEntryPoint") ; if loaded binary image would start executing at this address Local $pOptionalHeaderImageBase = DllStructGetData($tIMAGE_OPTIONAL_HEADER, "ImageBase") ; address of the first byte of the image when it's loaded in memory $pPointer += 8 ; skipping IMAGE_DIRECTORY_ENTRY_EXPORT ; Import Directory Local $tIMAGE_DIRECTORY_ENTRY_IMPORT = DllStructCreate("dword VirtualAddress; dword Size", $pPointer) ; Collect data Local $pAddressImport = DllStructGetData($tIMAGE_DIRECTORY_ENTRY_IMPORT, "VirtualAddress") Local $iSizeImport = DllStructGetData($tIMAGE_DIRECTORY_ENTRY_IMPORT, "Size") $pPointer += 8 ; size of $tIMAGE_DIRECTORY_ENTRY_IMPORT $pPointer += 24 ; skipping IMAGE_DIRECTORY_ENTRY_RESOURCE, IMAGE_DIRECTORY_ENTRY_EXCEPTION, IMAGE_DIRECTORY_ENTRY_SECURITY ; Base Relocation Directory Local $tIMAGE_DIRECTORY_ENTRY_BASERELOC = DllStructCreate("dword VirtualAddress; dword Size", $pPointer) ; Collect data Local $pAddressNewBaseReloc = DllStructGetData($tIMAGE_DIRECTORY_ENTRY_BASERELOC, "VirtualAddress") Local $iSizeBaseReloc = DllStructGetData($tIMAGE_DIRECTORY_ENTRY_BASERELOC, "Size") $pPointer += 8 ; size of IMAGE_DIRECTORY_ENTRY_BASERELOC $pPointer += 40 ; skipping IMAGE_DIRECTORY_ENTRY_DEBUG, IMAGE_DIRECTORY_ENTRY_COPYRIGHT, IMAGE_DIRECTORY_ENTRY_GLOBALPTR, IMAGE_DIRECTORY_ENTRY_TLS, IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG $pPointer += 40 ; skipping five more unused data directories ; Load the subrogor Local $pBaseAddress_OR = _WinAPI_LoadLibraryEx($sSubrogor, 1) ; "lighter" loading Local $pBaseAddress = $pBaseAddress_OR If @error Then Return SetError(4, 0, 0) ; Couldn't load subrogor Local $bCleanLoad = UnmapViewOfSection($pBaseAddress) If $bCleanLoad Then $pBaseAddress = _MemVirtualAlloc($pBaseAddress, $iSizeOfImage, $MEM_RESERVE + $MEM_COMMIT, $PAGE_READWRITE) ; In case of any error make corrections If @error Or $pBaseAddress = 0 Then $pBaseAddress = $pBaseAddress_OR $bCleanLoad = False EndIf Local $pHeadersNew = DllStructGetPtr($tIMAGE_DOS_HEADER) ; starting address of binary image headers Local $iOptionalHeaderSizeOfHeaders = DllStructGetData($tIMAGE_OPTIONAL_HEADER, "SizeOfHeaders") ; the size of the MS-DOS stub, the PE header, and the section headers ; Set proper memory protection for writing VirtualProtect($pBaseAddress, $iOptionalHeaderSizeOfHeaders, $PAGE_READWRITE) If @error Then _WinAPI_FreeLibrary($pBaseAddress) Return SetError(6, 0, 0) ; Couldn't set writing right for the headers EndIf ; Write NEW headers DllStructSetData(DllStructCreate("byte[" & $iOptionalHeaderSizeOfHeaders & "]", $pBaseAddress), 1, DllStructGetData(DllStructCreate("byte[" & $iOptionalHeaderSizeOfHeaders & "]", $pHeadersNew), 1)) ; Dealing with sections. Will write them. Local $tIMAGE_SECTION_HEADER Local $iSizeOfRawData, $pPointerToRawData Local $iVirtualSize, $iVirtualAddress Local $tImpRaw, $tRelocRaw For $i = 1 To $iNumberOfSections $tIMAGE_SECTION_HEADER = DllStructCreate("char Name[8];" & _ "dword VirtualSize;" & _ "dword VirtualAddress;" & _ "dword SizeOfRawData;" & _ "dword PointerToRawData;" & _ "dword PointerToRelocations;" & _ "dword PointerToLinenumbers;" & _ "word NumberOfRelocations;" & _ "word NumberOfLinenumbers;" & _ "dword Characteristics", _ $pPointer) ; Collect data $iSizeOfRawData = DllStructGetData($tIMAGE_SECTION_HEADER, "SizeOfRawData") $pPointerToRawData = $pHeadersNew + DllStructGetData($tIMAGE_SECTION_HEADER, "PointerToRawData") $iVirtualAddress = DllStructGetData($tIMAGE_SECTION_HEADER, "VirtualAddress") $iVirtualSize = DllStructGetData($tIMAGE_SECTION_HEADER, "VirtualSize") If $iVirtualSize And $iVirtualSize < $iSizeOfRawData Then $iSizeOfRawData = $iVirtualSize ; Set MEM_EXECUTE_READWRITE for sections (PAGE_EXECUTE_READWRITE for all for simplicity) VirtualProtect($pBaseAddress + $iVirtualAddress, $iVirtualSize, $PAGE_EXECUTE_READWRITE) If @error Then ; unavailable space. Will skip it and see what happens. $pPointer += 40 ; size of $tIMAGE_SECTION_HEADER structure ContinueLoop EndIf ; Clean the space DllStructSetData(DllStructCreate("byte[" & $iVirtualSize & "]", $pBaseAddress + $iVirtualAddress), 1, DllStructGetData(DllStructCreate("byte[" & $iVirtualSize & "]"), 1)) ; If there is data to write, write it If $iSizeOfRawData Then DllStructSetData(DllStructCreate("byte[" & $iSizeOfRawData & "]", $pBaseAddress + $iVirtualAddress), 1, DllStructGetData(DllStructCreate("byte[" & $iSizeOfRawData & "]", $pPointerToRawData), 1)) EndIf ; Imports If $iVirtualAddress <= $pAddressImport And $iVirtualAddress + $iSizeOfRawData > $pAddressImport Then $tImpRaw = DllStructCreate("byte[" & $iSizeImport & "]", $pPointerToRawData + ($pAddressImport - $iVirtualAddress)) FixImports($tImpRaw, $pBaseAddress) EndIf ; Relocations If $iVirtualAddress <= $pAddressNewBaseReloc And $iVirtualAddress + $iSizeOfRawData > $pAddressNewBaseReloc Then $tRelocRaw = DllStructCreate("byte[" & $iSizeBaseReloc & "]", $pPointerToRawData + ($pAddressNewBaseReloc - $iVirtualAddress)) EndIf ; Move pointer $pPointer += 40 ; size of $tIMAGE_SECTION_HEADER structure Next ; Fix relocations If $pAddressNewBaseReloc And $iSizeBaseReloc Then FixReloc($tRelocRaw, $pBaseAddress, $pOptionalHeaderImageBase, $iMagic = 523) ; Entry point address Local $pEntryFunc = $pBaseAddress + $iEntryPoint ; DllMain simulation If $iEntryPoint Then DllCallAddress("bool", $pEntryFunc, "ptr", $pBaseAddress, "dword", 1, "ptr", 0) ; DLL_PROCESS_ATTACH ; Get pseudo-handle Local $hPseudo = DllOpen($sSubrogor) If $bCleanLoad Then _WinAPI_FreeLibrary($pBaseAddress) ; decrement reference count ; Remove subrogor from list of loaded modules so it can be reused if necessary DeattachSubrogor($sSubrogor) ; call with second argument if you know what you're doing Return $hPseudo EndFunc Func FixReloc($tData, $pAddressNew, $pAddressOld, $fImageX64) Local $iDelta = $pAddressNew - $pAddressOld ; dislocation value Local $iSize = DllStructGetSize($tData) ; size of data Local $pData = DllStructGetPtr($tData) ; addres of the data structure Local $tIMAGE_BASE_RELOCATION, $iRelativeMove Local $iVirtualAddress, $iSizeofBlock, $iNumberOfEntries Local $tEnries, $iData, $tAddress Local $iFlag = 3 + 7 * $fImageX64 ; IMAGE_REL_BASED_HIGHLOW = 3 or IMAGE_REL_BASED_DIR64 = 10 While $iRelativeMove < $iSize ; for all data available $tIMAGE_BASE_RELOCATION = DllStructCreate("dword VirtualAddress; dword SizeOfBlock", $pData + $iRelativeMove) $iVirtualAddress = DllStructGetData($tIMAGE_BASE_RELOCATION, "VirtualAddress") $iSizeofBlock = DllStructGetData($tIMAGE_BASE_RELOCATION, "SizeOfBlock") $iNumberOfEntries = ($iSizeofBlock - 8) / 2 $tEnries = DllStructCreate("word[" & $iNumberOfEntries & "]", DllStructGetPtr($tIMAGE_BASE_RELOCATION) + 8) ; Go through all entries For $i = 1 To $iNumberOfEntries $iData = DllStructGetData($tEnries, 1, $i) If BitShift($iData, 12) = $iFlag Then ; check type $tAddress = DllStructCreate("ptr", $pAddressNew + $iVirtualAddress + BitAND($iData, 0xFFF)) ; the rest of $iData is offset DllStructSetData($tAddress, 1, DllStructGetData($tAddress, 1) + $iDelta) ; this is what's this all about EndIf Next $iRelativeMove += $iSizeofBlock WEnd Return 1 ; all OK! EndFunc Func FixImports($tData, $hInstance) Local $pImportDirectory = DllStructGetPtr($tData) Local $hModule, $pFuncName, $tFuncName, $sFuncName, $pFuncAddress Local $tIMAGE_IMPORT_MODULE_DIRECTORY, $pModuleName, $tModuleName Local $tBufferOffset2, $iBufferOffset2 Local $iInitialOffset, $iInitialOffset2, $iOffset Local Const $iPtrSize = DllStructGetSize(DllStructCreate("ptr")) While 1 $tIMAGE_IMPORT_MODULE_DIRECTORY = DllStructCreate("dword RVAOriginalFirstThunk;" & _ "dword TimeDateStamp;" & _ "dword ForwarderChain;" & _ "dword RVAModuleName;" & _ "dword RVAFirstThunk", _ $pImportDirectory) If Not DllStructGetData($tIMAGE_IMPORT_MODULE_DIRECTORY, "RVAFirstThunk") Then ExitLoop ; the end $pModuleName = $hInstance + DllStructGetData($tIMAGE_IMPORT_MODULE_DIRECTORY, "RVAModuleName") $tModuleName = DllStructCreate("char Name[" & _WinAPI_StringLenA($pModuleName) & "]", $hInstance + DllStructGetData($tIMAGE_IMPORT_MODULE_DIRECTORY, "RVAModuleName")) $hModule = _WinAPI_LoadLibrary(DllStructGetData($tModuleName, "Name")) ; load the module $iInitialOffset = $hInstance + DllStructGetData($tIMAGE_IMPORT_MODULE_DIRECTORY, "RVAFirstThunk") $iInitialOffset2 = $hInstance + DllStructGetData($tIMAGE_IMPORT_MODULE_DIRECTORY, "RVAOriginalFirstThunk") If $iInitialOffset2 = $hInstance Then $iInitialOffset2 = $iInitialOffset $iOffset = 0 ; back to 0 While 1 $tBufferOffset2 = DllStructCreate("ptr", $iInitialOffset2 + $iOffset) $iBufferOffset2 = DllStructGetData($tBufferOffset2, 1) ; value at that address If Not $iBufferOffset2 Then ExitLoop ; zero value is the end If BitShift(BinaryMid($iBufferOffset2, $iPtrSize, 1), 7) Then ; MSB is set for imports by ordinal, otherwise not $pFuncAddress = GetProcAddress($hModule, BitAND($iBufferOffset2, 0xFFFF)) ; the rest is ordinal value Else $pFuncName = $hInstance + $iBufferOffset2 + 2 $tFuncName = DllStructCreate("word Ordinal; char Name[" & _WinAPI_StringLenA($pFuncName) & "]", $hInstance + $iBufferOffset2) $sFuncName = DllStructGetData($tFuncName, "Name") $pFuncAddress = GetProcAddress($hModule, $sFuncName) EndIf DllStructSetData(DllStructCreate("ptr", $iInitialOffset + $iOffset), 1, $pFuncAddress) ; and this is what's this all about $iOffset += $iPtrSize ; size of $tBufferOffset2 WEnd $pImportDirectory += 20 ; size of $tIMAGE_IMPORT_MODULE_DIRECTORY WEnd Return 1 ; all OK! EndFunc Func UnmapViewOfSection($pAddress) Local $aCall = DllCall("ntdll.dll", "int", "NtUnmapViewOfSection", _ "handle", _WinAPI_GetCurrentProcess(), _ "ptr", $pAddress) If @error Or $aCall[0] Then Return SetError(1, 0, False) ; Failure Return True EndFunc Func VirtualProtect($pAddress, $iSize, $iProtection) Local $aCall = DllCall("kernel32.dll", "bool", "VirtualProtect", "ptr", $pAddress, "dword_ptr", $iSize, "dword", $iProtection, "dword*", 0) If @error Or Not $aCall[0] Then Return SetError(1, 0, 0) Return 1 EndFunc Func GetProcAddress($hModule, $vName) Local $sType = "str" If IsNumber($vName) Then $sType = "word" ; if ordinal value passed Local $aCall = DllCall("kernel32.dll", "ptr", "GetProcAddress", "handle", $hModule, $sType, $vName) If @error Or Not $aCall[0] Then Return SetError(1, 0, 0) Return $aCall[0] EndFunc Func DeattachSubrogor($sSubrogor, $sNewName = Default) If $sNewName = Default Then $sNewName = "~L" & Random(100, 999, 1) & ".img" ; some semi-random name by default ; Define PROCESS_BASIC_INFORMATION structure Local $tPROCESS_BASIC_INFORMATION = DllStructCreate("dword_ptr ExitStatus;" & _ "ptr PebBaseAddress;" & _ "dword_ptr AffinityMask;" & _ "dword_ptr BasePriority;" & _ "dword_ptr UniqueProcessId;" & _ "dword_ptr InheritedFromUniqueProcessId") ; Fill it with data Local $aCall = DllCall("ntdll.dll", "long", "NtQueryInformationProcess", _ "handle", _WinAPI_GetCurrentProcess(), _ "dword", 0, _ ; ProcessBasicInformation "ptr", DllStructGetPtr($tPROCESS_BASIC_INFORMATION), _ "dword", DllStructGetSize($tPROCESS_BASIC_INFORMATION), _ "dword*", 0) If @error Then Return SetError(1, 0, 0) ; failure while calling NtQueryInformationProcess Local $pPEB = DllStructGetData($tPROCESS_BASIC_INFORMATION, "PebBaseAddress") ; read the PEB address ; Construct the struct at that address. That's PEB struct only cutt-of for brevity Local $tPEB_Small = DllStructCreate("byte InheritedAddressSpace;" & _ "byte ReadImageFileExecOptions;" & _ "byte BeingDebugged;" & _ "byte Spare;" & _ "ptr Mutant;" & _ "ptr ImageBaseAddress;" & _ "ptr LoaderData;", _ $pPEB) ; Read LoaderData address Local $pPEB_LDR_DATA = DllStructGetData($tPEB_Small, "LoaderData") ; http://msdn.microsoft.com/en-us/library/aa813708(v=vs.85).aspx Local $tPEB_LDR_DATA = DllStructCreate("byte Reserved1[8];" & _ "ptr Reserved2;" & _ "ptr InLoadOrderModuleList[2];" & _ "ptr InMemoryOrderModuleList[2];" & _ "ptr InInitializationOrderModuleList[2];", _ $pPEB_LDR_DATA) ; ...will manipulate InMemoryOrderModuleList (no particular reason why) Local $pPointer = DllStructGetData($tPEB_LDR_DATA, "InMemoryOrderModuleList", 2) Local $pEnd = $pPointer Local $tLDR_DATA_TABLE_ENTRY, $sModule While 1 ; Construct entry structure at this address. InLoadOrderModuleList is skipped. $tLDR_DATA_TABLE_ENTRY = DllStructCreate("ptr InMemoryOrderModuleList[2];" & _ "ptr InInitializationOrderModuleList[2];" & _ "ptr DllBase;" & _ "ptr EntryPoint;" & _ "ptr Reserved3;" & _ "word LengthFullDllName;" & _ "word LengtMaxFullDllName;" & _ "ptr FullDllName;" & _ "word LengthBaseDllName;" & _ "word LengtMaxBaseDllName;" & _ "ptr BaseDllName;", _ $pPointer) ; Read address of the new entry $pPointer = DllStructGetData($tLDR_DATA_TABLE_ENTRY, "InMemoryOrderModuleList", 2) If $pPointer = $pEnd Then ExitLoop ; Full circle done ; Read module name $sModule = DllStructGetData(DllStructCreate("wchar[" & DllStructGetData($tLDR_DATA_TABLE_ENTRY, "LengthBaseDllName") / 2 & "]", DllStructGetData($tLDR_DATA_TABLE_ENTRY, "BaseDllName")), 1) ; If it's subrogor then change the name If $sModule = $sSubrogor Then DllStructSetData(DllStructCreate("wchar[" & DllStructGetData($tLDR_DATA_TABLE_ENTRY, "LengthBaseDllName") / 2 & "]", DllStructGetData($tLDR_DATA_TABLE_ENTRY, "BaseDllName")), 1, $sNewName) Return 1 EndIf WEnd ; If here something went wrong: Return SetError(2, 0, 0) EndFunc ;********************************************************************************************; UEZ 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
Gianni Posted July 16, 2022 Posted July 16, 2022 @Resiak1811 ...... forget the above, ...although it can still be an interesting change ... for your specific problem maybe it is enough to insert this line of code at the beginning of the example program: #AutoIt3Wrapper_UseX64=N Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
UEZ Posted July 16, 2022 Author Posted July 16, 2022 (edited) @Giannithank you for your memory call version of the UDF. The DLL exists only for x86 code execution and updated the UDF + examples that should cover the case if script runs as x64. Edited July 16, 2022 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
Resiak1811 Posted July 17, 2022 Posted July 17, 2022 sorry for the delay, I was off for the weekend.. thanks Gianni With #AutoIt3Wrapper_UseX64=N it work ... Nice job UEZ on this script !!
Resiak1811 Posted July 19, 2022 Posted July 19, 2022 Hi again I wonder if there a way to have bigger text(adaptative in size) and smaller(in height / fixed height) barcode ? When I say "bigger text(adaptative in size)" I mean if the text is 5 caracters (like: 12345) it can be bigger (like in font size 14) and if it's a long text 12345678987654321 (it should be in font size 😎 ** font size 14 and font size 8 are not a real size, just a example ** Something like that :
UEZ Posted July 20, 2022 Author Posted July 20, 2022 Although there is a fontsize definition in the struct it doesn't work for raster image output. The only setting I found is for output_options: $t_zint_symbol.output_options = $SMALL_TEXT For more details have a look here: https://zint.org.uk/manual/chapter/5#adjusting-other-output-options Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
UEZ Posted July 20, 2022 Author Posted July 20, 2022 (edited) I added a 3rd example using ZBarcode_Encode_and_Buffer_Vector function which more flexibility text format. Just check out post#1 Edited July 20, 2022 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
Resiak1811 Posted July 20, 2022 Posted July 20, 2022 1) small error in this line (call with wrong number of args.): ;~ _GDIPlus_GraphicsDrawString($hCanvas, $sText, ($tVector_String.width - $tVector_String.length * $tVector_String.fsize * 0.55) / 2, $tVector.heigth - $tVector_String.fsize * 1.33333, "Arial", $tVector_String.fsize * 0.75, 0, 0xFF000000) should be (need to removed the 0, before 0xFF000000): _GDIPlus_GraphicsDrawString($hCanvas, $sText, ($tVector_String.width - $tVector_String.length * $tVector_String.fsize * 0.55) / 2, $tVector.heigth - $tVector_String.fsize * 1.33333, "Arial", $tVector_String.fsize * 0.75, 0xFF000000) 2) I have mod. this line : _GDIPlus_GraphicsFillRect($hCanvas, $tVector_Rect.x, $tVector_Rect.y, $tVector_Rect.width, $tVector_Rect.height, $hBrush) to : _GDIPlus_GraphicsFillRect($hCanvas, $tVector_Rect.x, $tVector_Rect.y, $tVector_Rect.width, ($tVector_Rect.height / 2), $hBrush) so now we have half-height for the barcode (just like I want) 3) after a few test, I'm able to auto-size the text but need to make more test, if I'm able to do what I really want, I will post the code later. thank you for the 3rd example
Resiak1811 Posted July 21, 2022 Posted July 21, 2022 (edited) here it is.. auto-resize text : (I used a few line of code from Code128Auto.au3) expandcollapse popup#include <File.au3> #include <GUIConstantsEx.au3> #include <GDIPlus.au3> #include <StringSize.au3> #include "Zint.au3" $LabelWidth = 29 $LabelLenght = 90 $FontSize = 24 Global $pZB = ZBarcode_Create() If @error Then Exit MsgBox(16, "ERROR", "An error occured!" & @CRLF & "Error code = " & @error, 10) ;~ Global $t_zint_symbol = DllStructCreate($tag_zint_symbol, $pZB), $sText = "12340984576456789 ;-)" ;~ Global $t_zint_symbol = DllStructCreate($tag_zint_symbol, $pZB), $sText = "12340 ;-)" Global $t_zint_symbol = DllStructCreate($tag_zint_symbol, $pZB), $sText = "12 ;-)" With $t_zint_symbol .symbology = $BARCODE_CODE128 .scale = 1 ;~ .width = $LabelLenght ;~ not working .. need to test that?? .height = $LabelWidth EndWith If Not ZBarcode_Encode_and_Buffer_Vector($pZB, $sText) Then Exit MsgBox(16, "ERROR", "Unable to encode!" & @CRLF & "Error code = " & @error, 10) Global $tVector = DllStructCreate($tag_zint_vector, $t_zint_symbol.vector) Global $tVector_Rect = DllStructCreate($tag_zint_vector_rect, $tVector.rectangles) _GDIPlus_Startup() Global $hBitmap = _GDIPlus_BitmapCreateFromScan0($tVector.width, $tVector.heigth, $GDIP_PXF24RGB), $hCanvas = _GDIPlus_ImageGetGraphicsContext($hBitmap), $hBrush = _GDIPlus_BrushCreateSolid() _GDIPlus_GraphicsClear($hCanvas, 0xFFFFFFFF) _GDIPlus_BrushSetSolidColor($hBrush, BitAND($tVector_Rect.colour, 0xFF000000)) ;~ don't need to be in the While While $tVector_Rect.Next _GDIPlus_GraphicsFillRect($hCanvas, $tVector_Rect.x / 2, $tVector_Rect.y / 2, $tVector_Rect.width / 2, ($tVector_Rect.height / 2), $hBrush) ;~ working line $tVector_Rect = DllStructCreate($tag_zint_vector_rect, $tVector_Rect.Next) WEnd Global $tVector_String = DllStructCreate($tag_zint_vector_string, $tVector.strings) $i = _StringSize(String($sText), $FontSize, Default, Default, "Arial Black") $cx = ($LabelLenght / 2) - ($i[2] * 1.16 / 2) While $cx < 0 $FontSize -= 1 $i = _StringSize(String($sText), $FontSize, Default, Default, "Arial Black") $cx = ($LabelLenght / 2) - ($i[2] * 1.16 / 2) WEnd _GDIPlus_GraphicsSetTextRenderingHint($hCanvas, 3) If $FontSize < 10 Then $FontSize = 10 _GDIPlus_GraphicsDrawString($hCanvas, $sText, 0, ($LabelWidth / 2) + ($tVector_Rect.height / 2) - ($FontSize / 2), "Arial Black", $FontSize) Global Const $hGUI = GUICreate("Test Bar Code 128", $tVector.width, $tVector.heigth) GUISetState(@SW_SHOW) Global Const $hGfx = _GDIPlus_GraphicsCreateFromHWND($hGUI) _GDIPlus_GraphicsDrawImageRect($hGfx, $hBitmap, 0, 0, $tVector.width, $tVector.heigth) _GDIPlus_GraphicsDispose($hCanvas) _GDIPlus_GraphicsDispose($hGfx) _GDIPlus_ImageDispose($hBitmap) _GDIPlus_BrushDispose($hBrush) _GDIPlus_Shutdown() ZBarcode_Delete($pZB) Do Until GUIGetMsg() = $GUI_EVENT_CLOSE Edited July 21, 2022 by Resiak1811 UEZ 1
wakillon Posted September 13 Posted September 13 Hi UEZ What version is your Zint DLL? The 2.11? The last 2.15 (zint2150t.dll) on Sourceforge has only 3 functions instead of 25, so no update available ? AutoIt 3.3.18.0 X86 - SciTE 5.5.7 - WIN 11 24H2 X64 - Other Examples Scripts
UEZ Posted September 14 Author Posted September 14 I compiled Zint v2.15.09 source and it has 30 functions! ZBarcode_BarcodeName|0x0001CBA0 ZBarcode_Buffer|0x0001CC20 ZBarcode_Buffer_Vector|0x0001CC60 ZBarcode_Cap|0x0001CCA0 ZBarcode_Clear|0x0001D270 ZBarcode_Create|0x0001D390 ZBarcode_Default_Xdim|0x0001D3C0 ZBarcode_Delete|0x0001D5D0 ZBarcode_Dest_Len_ECI|0x0001D630 ZBarcode_Encode|0x0001D6D0 ZBarcode_Encode_File|0x0001D710 ZBarcode_Encode_File_and_Buffer|0x0001DB00 ZBarcode_Encode_File_and_Buffer_Vector|0x0001DB50 ZBarcode_Encode_File_and_Print|0x0001DBA0 ZBarcode_Encode_Segs|0x0001DBE0 ZBarcode_Encode_Segs_and_Buffer|0x0001E890 ZBarcode_Encode_Segs_and_Buffer_Vector|0x0001E8F0 ZBarcode_Encode_Segs_and_Print|0x0001E950 ZBarcode_Encode_and_Buffer|0x0001E990 ZBarcode_Encode_and_Buffer_Vector|0x0001EA10 ZBarcode_Encode_and_Print|0x0001EA90 ZBarcode_HaveGS1SyntaxEngine|0x0001EAF0 ZBarcode_NoPng|0x0001EB00 ZBarcode_Print|0x0001EB10 ZBarcode_Reset|0x0001EC30 ZBarcode_Scale_From_XdimDp|0x0001ECA0 ZBarcode_UTF8_To_ECI|0x0001EE80 ZBarcode_ValidID|0x0001EF40 ZBarcode_Version|0x0001EF80 ZBarcode_XdimDp_From_Scale|0x0001EF90 I will update the code in the next days. I compiled also a x64 Zint DLL but I don't know if it is working yet... argumentum, wakillon, KaFu and 1 other 4 Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
wakillon Posted September 15 Posted September 15 Thank you 🫡 AutoIt 3.3.18.0 X86 - SciTE 5.5.7 - WIN 11 24H2 X64 - Other Examples Scripts
UEZ Posted September 15 Author Posted September 15 (edited) UDF and DLL updated! See post#1. The DLLs are too big to post it here. You can find it on my 1Drv! Feel free to post examples here! Edited September 15 by UEZ mutleey and KaFu 2 Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
wakillon Posted September 15 Posted September 15 No problems, all examples work well The number of barcode types is impressive ! Nice work as usual AutoIt 3.3.18.0 X86 - SciTE 5.5.7 - WIN 11 24H2 X64 - Other Examples Scripts
UEZ Posted September 15 Author Posted September 15 (edited) I compiled the Zint DLLs again and integrated the PNG static lib. You should be able to save the image now as PNG. Edited September 15 by UEZ argumentum 1 Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now