CAPL Script

EncodeString

Syntax

long EncodeString(byte output[], long& encodedSize, long maxOutputSize, char input[], dword codepage);

Function

Encodes the stringinputwith the encodingcodepage. The length of the encoded string and a terminating “\0” depend on the requested encoding. The number of bytes used in theoutputbyte array is written toencodedSize. If the size of the output arraymaxOutputSizeis not sufficient to hold the encoded string and the “\0”, the functions returns an error and the content of the output array is undefined. Characters that cannot be represented in the requested encoding, are replaced with the best matching character, selected by the Windows functionWideCharToMultiByte.

Parameters

output Target byte array.

encodedSize EncodeString writes the number of bytes used in output (including the terminating “\0”) to this parameter.

maxOutputSize Size of the output array.

input The input string, using the current CAPL string encoding.

codepage Windows code page number for the encoded string.The include fileEncoding.cindefines the following code pages:

Return Values

0: Success, the byte array output and the resulting length encodedSize are 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[4] = "äöü";
byte stream[10];
long len;
result = EncodeString(stream, len, 10, text, CP_UTF8);
// on German Windows, len is now 7, stream is now {0xC3, 0xA4, 0xC3, 0xB6, 0xC3, 0xBC, 0}
if (result == 0) {...}
}

DecodeString | String Literal