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.

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.

4.2. DataMatrixEncode

The DataMatrixEncode function encodes data and returns a pointers that points to encoder result object.

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.

4.3. DataMatrixEncode2

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.

4.4. DataMatrixEncode2W

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.

4.5. DataMatrixResultGetSizeID

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.

4.6. DataMatrixResultGetBarcodeString

The DataMatrixResultGetBarcodeString function retrieves the barcode string that becomes a DataMatrix symbol after being formated with a DataMatrix font.

Parameters

[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.

4.7. DestroyDataMatrixEncodeResult

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.

4.8. PaintDataMatrixImageRaster

The PaintDataMatrixImageRaster function writes the DataMatrix barcode in raster image format specified to a disk file.