DecodeString
Syntax
long DecodeString(char output[], long outputSize, byte input[], long inputSize, dword codepage);
Function
Decodes the byte arrayinputfrom the encodingcodepageto the current CAPL string encoding. The length of the decoded string depends on the given encoding. If the size of the output arrayoutputSizeis not sufficient to hold the decoded string and a terminating “\0”, the functions returns an error and the content ofoutputis undefined. Characters that cannot be represented in the current encoding, are replaced with the best matching character, selected by the Windows functionWideCharToMultiByte.
Parameters
output Target char array.
outputSize
Size of the output array.
input
The input string in encodingcodepage, without BOM.
codepage
- CP_UTF8
- CP_UTF16
- CP_LATIN1
- CP_SHIFT_JIS
Return Values
0: Success, the byte arrayoutputis valid.
-1: Illegal character (e.g. illegal UTF8 code point).
-2: Insufficient buffer space, output array is too small.
-3: Internal error.
Example
... {
int result;
char text[10];
byte stream[6] = {0xC3, 0xA4, 0xC3, 0xB6, 0xC3, 0xBC};
result = DecodeString(text, 10, stream, 6, CP_UTF8);
// on German Windows, text is now {‘ä’, ‘ö’, ‘ü’, 0}
if (result == 0) {
write(text); // Output (on a German Windows): äöü
}
}
EncodeString | String Literal