Table of Contents
- 4.1. ImageTypeEnum
- 4.2. DataMatrixEncode
- 4.3. DataMatrixEncode2
- 4.4. DataMatrixEncode2W
- 4.5. DataMatrixResultGetSizeID
- 4.6. DataMatrixResultGetBarcodeString
- 4.7. DestroyDataMatrixEncodeResult
- 4.8. PaintDataMatrixImageRaster
- 4.9. PaintDataMatrixImageVector
- 4.10. PaintDataMatrixImageRaster2
- 4.11. PaintDataMatrixImageVector2
- 4.12. PaintDataMatrixImageEMF
- 4.13. DataMatrixGetErrorMessage
- 4.14. DataMatrixResultGetBarcodeString2
- 4.15. PaintDataMatrixImageClipboard
Creating DataMatrix barcodes using DLL APIs involves three steps.
The first
step is to call DataMatrixEncode
or DataMatrixEncode2
with data to encode and
size option. If this step succeeds, a pointer is returned from which you
can query the attributes of the barcode created, “paint” the
barcode into an image file, or obtain the barcode string.
Finally, you should call DestroyDataMatrixEncodeResult
to release the memory resource
used by the encoder result object.
Table 4.1. List of Enumerations
Enumeration | Comment |
---|---|
ImageTypeEnum | Image formats supported by the encoder. |
Table 4.2. List of Functions
Function | Comment |
---|---|
DataMatrixEncode | Encodes data and returns a pointers that points to encoder result object. |
DataMatrixEncode2 | Abbreviated version of DataMatrixEncode. |
DataMatrixEncode2W | The function DataMatrixEncode2W is added in 5.1 release to encode Unicode strings. |
DataMatrixResultGetSizeID | Retrieves the size ID of the datamatrix barcode created. |
DataMatrixResultGetBarcodeString | Retrieves the barcode string that becomes a DataMatrix symbol after being formated with a DataMatrix font. |
DestroyDataMatrixEncodeResult | Releases all resources allocated to the encoder result object. |
PaintDataMatrixImageRaster | Writes the DataMatrix barcode in raster image format specified to a disk file. |
PaintDataMatrixImageVector | Writes the DataMatrix barcode in vector image format specified to a disk file. |
PaintDataMatrixImageRaster2 | Writes the DataMatrix barcode in raster image format specified to IStream object. |
PaintDataMatrixImageVector2 | Writes the DataMatrix barcode in vector image format specified to an IStream object. |
PaintDataMatrixImageEMF | Creates a Windows Enhanced Meta File object and returns the handle. |
DataMatrixGetErrorMessage | Retrieves a string that describes the error. |
DataMatrixResultGetBarcodeString2 | Returns barcode string without requiring user to preallocate the buffer. |
PaintDataMatrixImageClipboard | Creates a Windows Enhanced Meta File object and place it into the clipboard. |
Image formats supported by the encoder.
enum ImageTypeEnum { IMAGE_PNG== 0, IMAGE_SVG== 1, IMAGE_EMF== 2, IMAGE_EPS== 3, IMAGE_BMP== 4 };
Remarks
The ImageTypeEnum enum has the following values:
Table 4.3. ImageTypeEnum Enumeration
Constant | Value | Comment |
---|---|---|
IMAGE_PNG | = 0 | PNG (Portable Network Graphics) |
IMAGE_SVG | = 1 | SVG (Scalable Vector Graphics) |
IMAGE_EMF | = 2 | EMF (Windows Enhanced MetaFile) |
IMAGE_EPS | = 3 | EPS (Encapsulated PostScript) |
IMAGE_BMP | = 4 | BMP (Windows Bitmap) |
PNG and BMP are raster formats, which store color information of individual pixels. SVG, EMF and EPS are vector graphics formats and contains drawing commands instead. If you are using raster graphic format, one pixel should be mapped to one or integral times pixels on the printer. If you are using vector graphics format, the drawing units should map to integral times pixels on the printer. They are referenced in the PaintDataMatrixImageRaster function and PaintDataMatrixImageVector function.
The DataMatrixEncode function encodes data and returns a pointers that points to encoder result object.
int __stdcall DataMatrixEncode( const char * dataToEncode, int sizeIDRequested, void ** ppResult );
Parameters
- dataToEncode
[in] Pointer to a null-terminated string containing the data to be encoded. You can use tilde codes to encode control characters such as NUL, as well as advanced features such as ECI and structural append. For more information, see Appendix B, Input format (ECI and Structural Append).
- sizeIDRequested
[in] An integer value that corresponds to the size ID of the datamatrix barcode. Since version 5.1, this parameter is enhanced to support additional parameters, such as encodation mode selection. See the manual for details.
- ppResult
A pointer to a pointer that points to the encode result created. Use this pointer to discover the actual attributes of the symbol created, or create image files.
Return Values
If the function succeeded, the return value is 0. If the function failed, it returns the error code. You can call function DataMatrixGetErrorMessage to obtain the description of the error.
Remarks
This function encodes the data according to the parameter specified, and returns a pointer from which you can retrieve the encoding result.
The function DataMatrixEncode2 is an abbreviated version of DataMatrixEncode.
void *__stdcall DataMatrixEncode2( const char * dataToEncode, int sizeIDRequested );
Parameters
- dataToEncode
[in] Pointer to a null-terminated string containing the data to be encoded. You can use tilde codes to encode control characters such as NUL, as well as advanced features such as ECI. For more information, see Appendix B, Input format (ECI and Structural Append).
- sizeIDRequested
[in] An integer value that corresponds to the size ID of the datamatrix barcode. Since version 5.1, this parameter is enhanced to support additional parameters, such as encodation mode selection. See the manual for details.
- ppResult
A pointer to a pointer that points to the encode result created. Use this pointer to discover the actual attributes of the symbol created, or create image files.
Return Values
If the function failed, the return value is 0 (NULL). If it succeeds, it returns a pointer that points to the result object. You should release the encoder result object by calling function DestroyDataMatrixEncodeResult.
Remarks
In this function, a pointer is returned instead of status code. A non-null return value indicates that no error occured. The pointer associated resource must be released by calling DestroyDataMatrixEncodeResult.
The function DataMatrixEncode2 is an abbreviated version of DataMatrixEncode.
The function DataMatrixEncode2W is added in 5.1 release to encode Unicode strings.
void *__stdcall DataMatrixEncode2W( const wchar_t * dataToEncode, int sizeIDRequested );
Parameters
- dataToEncode
[in] Pointer to a null-terminated string containing the data to be encoded. You can use tilde codes to encode control characters such as NUL, as well as advanced features such as ECI. For more information, see Appendix B, Input format (ECI and Structural Append).
- sizeIDRequested
[in] An integer value that corresponds to the size ID of the datamatrix barcode. Since version 5.1, this parameter is enhanced to support additional parameters, such as encodation mode selection. See the manual for details.
- ppResult
A pointer to a pointer that points to the encode result created. Use this pointer to discover the actual attributes of the symbol created, or create image files.
Return Values
If the function failed, the return value is 0 (NULL). If it succeeds, it returns a pointer that points to the result object. You should release the encoder result object by calling function DestroyDataMatrixEncodeResult.
Remarks
See the manual on the details how a wide string is handled. In this function, a pointer is returned instead of status code. A non-null return value indicates that no error occured. The pointer associated resource must be released by calling DestroyDataMatrixEncodeResult.
The DataMatrixResultGetSizeID function retrieves the size ID of the datamatrix barcode created.
int __stdcall DataMatrixResultGetSizeID( void * pEncodeResult );
Parameters
- pEncodeResult
[in] The pointer that points to the encoding result object, returned from DataMatrixEncode or DataMatrixEncode2 functions.
Return Values
The size ID of the DataMatrix barcode.
The DataMatrixResultGetBarcodeString function retrieves the barcode string that becomes a DataMatrix symbol after being formated with a DataMatrix font.
int __stdcall DataMatrixResultGetBarcodeString( void * pEncodeResult, char * buffer, unsigned int * maxSize, const char * eol );
Parameters
- pEncodeResult
[in] The pointer that points to the encoding result object, returned from DataMatrixEncode or DataMatrixEncode2 functions.
- buffer
[in] The pointer that points to a byte array that receives the string.
- maxSize
[in,out] Pointer to a variable that specifies the size of the buffer pointed to by the buffer parameter, in bytes. When the function returns, this variable contains the size of the data copied to buffer.
- eol
[in] Pointer to a NUL terminated string that will be appended to each row in the barcode string.
Return Values
If the function succeeded, it returns the length of the string (excluding terminating NUL character). If the funtion fails due to insufficient storage, it returns 0.
Remarks
When creating barcodes using font-based solution, you first call encoder function DataMatrixEncode or DataMatrixEncode2 to obtain a pointer that points to the result object. Then DataMatrixResultGetBarcodeString is called to obtain a string that becomes DataMatrix symbol after the font is applied. If memory is not an issue, allocate a large buffer with 8096 bytes to hold the largest DataMatrix barcode. This size is sufficient for the largest symbol with carriage return and line feed as line ending.
The DestroyDataMatrixEncodeResult function releases all resources allocated to the encoder result object.
void __stdcall DestroyDataMatrixEncodeResult( void * pResult );
Parameters
- pResult
[in] Pointer to the encoder result object.
Remarks
After the object is destroyed, the specific pointer pResult is no longer valid.
The PaintDataMatrixImageRaster function writes the DataMatrix barcode in raster image format specified to a disk file.
int __stdcall PaintDataMatrixImageRaster( void * pEncodeResult, const wchar_t * wszFilename, int pixelsPerModule, int forecolor, int backcolor, int imageType );
Parameters
- pEncodeResult
[in] Pointer that points to the encoder result object.
- wszFilename
[in] Pointer to the file name for the image file to be created.
- pixelsPerModule
[in] Number pixels per module with.
- forecolor
[in] Value of the foreground color, in RGB colorspace.
- backcolor
[in] Value of the background color, in RGB colorspace.
- imageType
[in] An integer that indicates the image file format. The current version supports two formats: PNG(0) and BMP(4).
Return Values
If the function failed, it returns the error code. You can call function DataMatrixGetErrorMessage to obtain the description of the error.
Remarks
Note: the order of the component bytes are R, G and B, which is opposite of COLORREF type on Windows.
The PaintDataMatrixImageVector function writes the DataMatrix barcode in vector image format specified to a disk file.
int __stdcall PaintDataMatrixImageVector( void * pEncodeResult, const wchar_t * wszFilename, int module_width_hm, int target_dpi, int forecolor, int backcolor, int imageType );
Parameters
- pEncodeResult
[in] Pointer that points to the encoder result object.
- wszFilename
[in] Pointer to the file name for the image file to be created.
- module_width_hm
[in] Module width (X dimension), in the unit of high metric. 1 unit high metric = 1/1000 cm.
- target_dpi
[in] The resolution of the target printer.
- forecolor
[in] Value of the foreground color, in RGB colorspace.
- backcolor
[in] Value of the background color, in RGB colorspace.
- imageType
[in] An integer that indicates the image file format. The current version supports three formats: SVG(1), EMF(2) and EPS(3).
Return Values
If the function failed, it returns the error code. You can call function DataMatrixGetErrorMessage to obtain the description of the error.
Remarks
Note: the order of the component bytes are R, G and B, which is opposite of COLORREF type on Windows.
The PaintDataMatrixImageRaster function writes the DataMatrix barcode in raster image format specified to IStream object.
int __stdcall PaintDataMatrixImageRaster2( void * pEncodeResult, IStream * ostream, int pixelsPerModule, int forecolor, int backcolor, int imageType );
Parameters
- pEncodeResult
[in] Pointer that points to the encoder result object.
- ostream
[in] Pointer to an IStream object.
- pixelsPerModule
[in] Number pixels per module with.
- forecolor
[in] Value of the foreground color, in RGB colorspace.
- backcolor
[in] Value of the background color, in RGB colorspace.
- imageType
[in] An integer that indicates the image file format. The current version supports two formats: PNG(0) and BMP(4).
Return Values
If the function failed, it returns the error code. You can call function DataMatrixGetErrorMessage to obtain the description of the error.
Remarks
Note: the order of the component bytes are R, G and B, which is opposite of COLORREF type on Windows.
The PaintDataMatrixImageVector function writes the DataMatrix barcode in vector image format specified to an IStream object.
int __stdcall PaintDataMatrixImageVector2( void * pEncodeResult, IStream * ostream, int module_width_hm, int target_dpi, int forecolor, int backcolor, int imageType );
Parameters
- pEncodeResult
[in] Pointer that points to the encoder result object.
- ostream
[in] Pointer to an IStream object.
- module_width_hm
[in] Module width (X dimension), in the unit of high metric. 1 unit high metric = 1/1000 cm.
- target_dpi
[in] The resolution of the target printer.
- forecolor
[in] Value of the foreground color, in RGB colorspace.
- backcolor
[in] Value of the background color, in RGB colorspace.
- imageType
[in] An integer that indicates the image file format. The current version supports three formats: SVG(1), EMF(2) and EPS(3).
Return Values
If the function failed, it returns the error code. You can call function DataMatrixGetErrorMessage to obtain the description of the error.
Remarks
Note: the order of the component bytes are R, G and B, which is opposite of COLORREF type on Windows.
The PaintDataMatrixImageClipboard function Creates a Windows Enhanced Meta File object and returns the handle.
HENHMETAFILE __stdcall PaintDataMatrixImageEMF( void * pEncodeResult, int module_len_hm, int target_dpi, int forecolor, int backcolor, int imageType );
Parameters
- pEncodeResult
[in] Pointer that points to the encoder result object.
- module_width_hm
[in] Module width (X dimension), in the unit of high metric. 1 unit high metric = 1/1000 cm.
- target_dpi
[in] The resolution of the target printer.
- forecolor
[in] Value of the foreground color, in RGB colorspace.
- backcolor
[in] Value of the background color, in RGB colorspace.
Return Values
If the function failed, it returns the error code. You can call function DataMatrixGetErrorMessage to obtain the description of the error.
Remarks
The caller should destory this handle after using.
The DataMatrixGetErrorMessage function retrieves a string that describes the error.
const char *__stdcall DataMatrixGetErrorMessage( int errorno );
Parameters
- errorno
[in] The error number.
Return Values
a read only string that describes the error.
Remarks
The string returned is a read only string. User should not modify the string directly.
The DataMatrixResultGetBarcodeString2 function returns barcode string without requiring user to preallocate the buffer.
const char *__stdcall DataMatrixResultGetBarcodeString2( void * pEncodeResult, const char * eol );
Parameters
- pEncodeResult
[in] The pointer that points to the encoding result object, returned from DataMatrixEncode or DataMatrixEncode2 functions.
- eol
[in] Pointer to a NUL terminated string that will be appended to each row in the barcode string.
Return Values
Pointer to a NUL terminated string that represents the barcode (barcode string). If the function failed due to insufficient memory, it returns NULL.
Remarks
The encoder result manages the buffer by itself. Caller should cache the string returned, but not the pointer, as the contents may change after another call of DataMatrixResultBarcodeString2 is made.
The PaintDataMatrixImageClipboard function Creates a Windows Enhanced Meta File object and place it into the clipboard.
int __stdcall PaintDataMatrixImageClipboard( void * pEncodeResult, int module_width_hm, int target_dpi, int forecolor, int backcolor );
Parameters
- pEncodeResult
[in] Pointer that points to the encoder result object.
- module_width_hm
[in] Module width (X dimension), in the unit of high metric. 1 unit high metric = 1/1000 cm.
- target_dpi
[in] The resolution of the target printer.
- forecolor
[in] Value of the foreground color, in RGB colorspace.
- backcolor
[in] Value of the background color, in RGB colorspace.
Return Values
If the function failed, it returns the error code. You can call function DataMatrixGetErrorMessage to obtain the description of the error.