There are some common traps and pitfalls when programs containing string
constants with non-ASCII characters are executed.
The following ways to store the source files have different implications:
- Store source file in local 8-bit encoding
Only native characters can be stored.
String constants that are created by the compiler are also encoded in
local 8-bit encoding, i.e. the execution charset is local 8-bit.
If strings in local 8-bit encoding are passed to HALCON C or HALCON/C++,
either change the interface default encoding (by calling
SetHcInterfaceStringEncodingIsUtf8(false) or
SetHcppInterfaceStringEncodingIsUtf8(false), respectively) or create the string that is
passed to HALCON with a suitable conversion function,
e.g., HString::FromLocal8Bit().
When using HALCON/C++ as an alternative,
the string constant can be created as wide character string with “L...”.
- Store source file in UTF-8 with or without BOM signature
The big advantage is that any Unicode characters can be stored.
To store files without BOM signature in Visual Studio, choose Unicode (UTF-8 without
signature) - Codepage 65001 in the Save As or Advanced Save
Options dialog.
Without BOM signature, the files are not automatically detected as UTF-8 files,
i.e. they are interpreted as local 8-bit files.
Files with BOM signature marker are correctly read as UTF-8 files.
However, the compiler converts the string constants automatically into
local 8-bit encoding, i.e. although the source charset is UTF-8, the
execution charset is still local 8-bit.
Hence, when passing these strings to HALCON, all points mentioned above are valid.
When using Visual Studio 2015 it is possible to set the compiler option
/utf-8.
You can add this option in Project Property Page > Configuration Properties > C/C++
> All Options > Additional Options.
If this option is set, both the source charset and the execution charset are
UTF-8 (which works also without the BOM signature).
In this case, all strings are UTF-8 and can directly be passed to HALCON.