Using the SoftekBarcode DLL with Python
The following code as been kindly contributed by a developer to show how to use the SoftekBarcode DLL interface with Python:
Python 3.7:
import ctypes
from ctypes import *
import os
# Load the dll
softekDLL = ctypes.OleDLL("C:\\tmp\\SoftekBarcodedll.dll")
# Create Barcode Instance and Set License Key
barCode1 = softekDLL.mtCreateBarcodeInstance()
# Set the license key
softekDLL.mtSetLicenseKey(barCode1, 'your license key'.encode('utf-8'))
# Scan some file
n = softekDLL.mtScanBarCode(barCode1,'\\path\\to\\some\\file.jpg'.encode('utf-8'))
# print the barcode
print (ctypes.c_char_p(softekDLL.mtGetBarString(barCode1,1)).value)
Python 2.7:
import ctypes
from ctypes import *
import os
# Set up the path to SoftekBarcode.dll
softek = r’C:\\Your\\Path\\To\\softek_barcode_sdk\\x86′
os.environ[‘PATH’] = ‘;’.join([softek, os.environ[‘PATH’]])
softekDLL = ctypes.OleDLL(os.path.join(softek, ‘SoftekBarcode.dll’))
# Create Barcode Instance and Set License Key
barCode1 = softekDLL.mtCreateBarcodeInstance()
softekDLL.mtSetLicenseKey(barCode1,’Your License Key’)
# Configure Scanner for DataMatrix w/Skew
softekDLL.mtSetReadDataMatrix(barCode1,True)
softekDLL.mtSetSkewedDatamatrix(barCode1,True)
softekDLL.mtSetSkewTolerance(barCode1,1)
# Scan a code and report on the findings
# c_char_p() effectively casts the result to a char string
n = softekDLL.mtScanBarCode(barCode1,’C:\\Your\\Path\\To\\DSCN3724.JPG’)
print “%s %s Found” % (n,c_char_p(softekDLL.mtGetBarStringType(barCode1,1)).value)
print c_char_p(softekDLL.mtGetBarString(barCode1,1)).value