BinaryConvert

Converts a binary buffer.

Syntax:

BinaryConvert( handle, source-type, target-type, code-page, flags )

Parameters:

(i) handle: handle of buffer.

(i) source-type: format of existing data in buffer.

(i) target-type: format of data which the buffer will be converted to.

(i) code-page: code page for 8-bit <-> Unicode conversions.

(i) flags: additional options.

Returns:

(i) Returns the new binary EOD (end of data) for the buffer.

 

This function can be used to perform the following types of conversions:

8-bit <-> Unicode

Multibyte <-> Unicode

ANSI <-> OEM

-> Uppercase

-> Lowercase

 

"Source-type" and "target-type" can be one of the following:

0 8-bit ANSI

1 8-bit OEM

2 Multibyte (eg, double-byte)

3 Unicode

 

Conversions from 8-bit (types 0 or 1) to or from multibyte (type 2) are not supported. If you need to perform this type of conversion, you can do it in two steps, using Unicode as an intermediate stage (eg, ANSI to Unicode, then Unicode to multibyte).

 

For conversions to or from Unicode, a code page must be specified for the 8-bit (non-Unicode) character set. "Code-page" can be any valid code page on your system, or one of the following default code pages:

0 ANSI

1 OEM

2 Macintosh

 

For conversions which don't involve Unicode, "code-page" is ignored.

 

"Flags" can be one of the following:

0 none of the following apply

1 Convert to uppercase

2 Convert to lowercase

 

Note: that Unicode uses two bytes for each character. Therefore, for conversions to Unicode, the binary buffer must be large enough to hold at least twice as much data as is currently in the buffer. i.e., if you are trying to convert a buffer which contains a 40-character string to Unicode, the buffer must be at least 80 bytes in size, because the resulting Unicode string will be 80 bytes long.

 

Example:


buf = BinaryAlloc(20)
BinaryPokeStr(buf, 0, "Helloß")
rc = ""
STRING = BinaryPeekStr(buf, 0, BinaryEodGet(buf))
Message(rc, STRING)
rc = BinaryConvert(buf, 2, 3, 0, 1)
STRING = BinaryPeekStr(buf, 0, BinaryEodGet(buf))
Message(rc, STRING)
See Also:

Binary Operations, BinaryAlloc, BinaryCopy, BinaryFree, BinaryRead, DllCall