cwbNL_ConvertCodePagesEx

Use the cwbNL_ConvertCodePagesEx command.

Purpose

Convert strings from one code page to another. This API combines the following three converter APIs for the default conversion:

  • cwbNL_CreateConverterEx
  • cwbNL_Convert
  • cwbNL_DeleteConverter

Syntax

 
unsigned int CWB_ENTRY cwbNL_ConvertCodePagesEx(
                             unsigned long   sourceCodePage,
                             unsigned long   targetCodePage,
                             unsigned long   sourceLength,
                             unsigned long   targetLength,
                             char           *sourceBuffer,
                             char           *targetBuffer,
                             unsigned long  *numberOfErrors,
                             unsigned long  *positionOfFirstError,
                             unsigned long  *requiredLen,
                             cwbSV_ErrHandle errorHandle);

Parameters

unsigned long sourceCodePage - input
Code page of the data in the source buffer.
unsigned long targetCodePage - input
Code page to which the data should be converted.
unsigned long sourceLength - input.
Length of the source buffer
unsigned long targetLength - input.
Length of the target buffer
char *sourceBuffer - input
Buffer containing the data to convert.
char *targetBuffer - output
Buffer to contain the converted data.
unsigned long *numberOfErrors - output
Contains the number of characters that could not be converted properly.
unsigned long *positionOfFirstError - output
Contains the offset of the first character in the source buffer that could not be converted properly.
unsigned long *requiredLen - output
Actual length of the result. If requiredLen > resultLen, the return value will be CWB_BUFFER_OVERFLOW.
cwbSV_ErrHandle errorHandle - output
Handle to an error object. Any returned messages will be written to this object. It is created with the cwbSV_CreateErrHandle API. The messages may be retrieved with the cwbSV_GetErrText API. If the parameter is set to zero, no messages will be retrievable.

Return Codes

The following list shows common return values.

CWB_OK
Successful completion.
CWB_INVALID_HANDLE
Invalid handle.
CWB_INVALID_POINTER
NULL passed on output parameter.
CWBNL_ERR_CNV_UNSUPPORTED
An error occurred while attempting to convert the characters. No conversion was done. The most common reason is that a conversion table is missing. Conversion tables are either installed with the product, or retrieved from the default system when needed. There may have been some problem communicating with the default system.
CWBNL_ERR_CNV_ERR_STATUS
This return code is used to indicate that while the requested conversion is supported, and the conversion completed, there were some characters that did not convert properly. Either the source buffer contained null characters, or the characters do not exist in the target code page. Applications can choose to ignore this return code or treat it as a warning.
CWB_NOT_ENOUGH_MEMORY
Insufficient memory.

Usage

The following values may be specified on the sourceCodePage and the targetCodePage parameters:

Value Meaning
CWBNL_CP_UNICODE_F200 UCS2 Version 1.1 UNICODE
CWBNL_CP_UNICODE UCS2 Current Version UNICODE
CWBNL_CP_AS400 IBM® i host code page
CWBNL_CP_CLIENT_OEM OEM client code page
CWBNL_CP_CLIENT_ANSI ANSI client code page
CWBNL_CP_CLIENT_UNICODE UNICODE client code page
CWBNL_CP_UTF8 UCS transformation form, 8–bit format
CWBNL_CP_CLIENT Generic client code page. Default is CWBNL_CP_CLIENT_OEM. CWBNL_CP_CLIENT is set to CWBNL_CP_CLIENT_ANSI when CWB_ANSI is defined, to CWBNL_CP_CLIENT_UNICODE when CWB_UNICODE is defined and to CWBNL_CP_CLIENT_OEM when CWB_OEM is defined.
CWBNL_CP_UTF16BE UTF-16 (Big-Endian)
CWBNL_CP_UTF16LE UTF-16 (Little-Endian)
CWBNL_CP_UTF16 CWBNL_CP_UTF16BE or CWBNL_CP_UTF16LE, depending on the platform
CWBNL_CP_UTF32BE UTF-32 (Big-Endian)
CWBNL_CP_UTF32LE UTF-34 (Little-Endian)
CWBNL_CP_UTF32 CWBNL_CP_UTF32BE or CWBNL_CP_UTF32LE, depending on the platform