7.9. Data Type Issues

When working with our DLL interface, pay attention to the boolean type and the string type used by exported functions. See below for details.

7.9.1. Boolean Type

For the convenience of classic Visual Basic developers, all boolean variables are defines as VARIANT_BOOL type. The VARIANT_BOOL is a little bit different from the BOOL in C and boolean type in C++ languages. To tell a value is true or not, compare it with 0 (or FALSE in C, false in C++) other than comparing it with TRUE values.

For example, suppose the variable rc is defined as VARIANT_BOOL type. To tell rc is TRUE or not, use

if (rc)

or

if (rc=false)

It will not work as expected if you compare the value with true, as below

if (rc==true)

The .Net framework implicitly converts VARIANT_BOOL to boolean. As long as you declare the variable as bool or Boolean, you do not need to worry about this in a .net program.

7.9.2. String Type

When you use DLL functions to retrieve a string type property, you need to supply a buffer large enough to hold the data. You can use 1024 as a reasonable buffer size. For example, the following code retrieve the Message property of the barcode object:

char message[1024];
get_Message(handle, message);

For performance reasons, Barcode DLL does not check if the buffer is long enough. Consequently the buffer overrun may happen if the buffer size is too small.

In Visual Basic, the default String type does not have a buffer at all. Passing an empty string will crash Barcode DLL. You should never use a zero-length string to retrieve a string type property. Instead, use the code below:

Dim strDefaultValue As String * 1024
Dim rc As Long
rc = get_Message(barcode_object_handle, 
         strDefaultValue)

In .Net program, you need to use StringBuilder class to retrieve the string results. Refer to our sample for details.