WideCharToMultiByte

Aus API-Wiki
Zur Navigation springenZur Suche springen

Die API-Funktion WideCharToMultiByte konvertiert eine Zeichenfolge der Unicode-Kodierung UTF-16 (WideChar) in einen einbyte/mehrbyte-Character-String.

Declare Function WideCharToMultiByte lib "kernel32.dll" ( _
                 ByVal CodePage As Long, _
                 ByVal dwFlags As Long, _
                 ByVal lpWideCharStr As String, _
                 ByVal cchWideChar As Long, _
                 ByVal lpMultiByteStr As String, _
                 ByVal cbMultiByte As Long, _
                 ByVal lpDefaultChar As String, _
                 ByVal lpUsedDefaultChar As Long) As Long

Parameter

CodePage

[in] die Codepage die bei der Konversion verwendet werden soll. Es kann jede im System installierte Codepage verwendet werden oder eine aus der folgenden Liste. Die Liste ist nicht vollständig sie zeigt nur mögliche Werte:
Private Const CP_ACP        As Long = 0     ' ANSI Code Page
Private Const CP_OEMCP      As Long = 1     ' OEM Code page
Private Const CP_MACCP      As Long = 2     '
Private Const CP_THREAD_ACP As Long = 3     '
Private Const CP_SYMBOL     As Long = 42    '
Private Const CP_ISO8859_4  As Long = 28594 ' Baltisch
Private Const CP_ISO8859_15 As Long = 28605 ' Lateinisch 9
Private Const CP_UTF7       As Long = 65000 ' UTF-7 code page
Private Const CP_UTF8       As Long = 65001 ' UTF-8 code page
' Die Werte der Konstanten kann man auch in der Regions-Einstellung nachlesen.
' siehe: Systemsteuerung->Regions und Sprachoptionen->Erweitert->Codepagekonvertierungstabelle

für eine komplette Liste siehe Code Page Identifiers

(When SYSGEN_LOCUSA is set, only the 1252 and 437 code pages are supported)

dwFlags

[in] Handling of unmapped characters. The function performs more quickly when none of these flags is set. The flag constants are described in the following table.
Private Const WC_DISCARDNS      As Long = &H10
Private Const WC_SEPCHARS       As Long = &H20
Private Const WC_DEFAULTCHAR    As Long = &H40
Private Const WC_COMPOSITECHECK As Long = &H200

When WC_COMPOSITECHECK is specified, the function converts composite characters to precomposed characters. A composite character consists of a base character and a nonspacing character, each having different character values. A precomposed character has a single character value for a base/nonspacing character combination. In the character è, the e is the base character, and the accent grave mark is the nonspacing character. When an application specifies WC_COMPOSITECHECK, it can use the last three flags in this list (WC_DISCARDNS, WC_SEPCHARS, and WC_DEFAULTCHAR) to customize the conversion to precomposed characters. These flags determine the function's behavior when there is no precomposed mapping for a base/nonspace character combination in a wide-character string. These last three flags can only be used if the WC_COMPOSITECHECK flag is set. The function's default behavior is to generate separate characters (WC_SEPCHARS) for unmapped composite characters.

lpWideCharStr

[in] Zeiger auf die UTF-16-String, der konvertiert werden soll.

cchWideChar

[in] Größe in UTF-16-Codeeinheiten. Wenn hier -1 angegeben wird und der String mit einem Nullzeichen terminiert ist, so wird die Länge automatsich ermittelt.

lpMultiByteStr

[out] Zeiger auf einen Puffer von 8-Bit-Zeichen der den übersetzten String empfangen soll.

cbMultiByte

[in] Größe, in Bytes, des Puffers. Wenn hier 0 angegeben wird so liefert die Funktion die Anzahl an erforderlichen Bytes zurück, ohne die Übersetzung durchzuführen.

lpDefaultChar

[in] Pointer to the character to use if a wide character cannot be represented in the specified code page. The application sets this parameter to a null pointer if the function is to use a system default value. To obtain the system default character, the application can call the GetCPInfo or GetCPInfoEx function.

For the CP_UTF7 and CP_UTF8 settings for CodePage, this parameter must be set to a null pointer. Otherwise, the function fails with ERROR_INVALID_PARAMETER

lpUsedDefaultChar

[out] Pointer to a flag that indicates if the function has used a default character in the conversion. The flag is set to TRUE if one or more characters in the source string cannot be represented in the specified code page. Otherwise, the flag is set to FALSE. This parameter can be set to a null pointer.

For the CP_UTF7 and CP_UTF8 settings for CodePage, this parameter must be set to a null pointer. Otherwise, the function fails with ERROR_INVALID_PARAMETER.

Rückgabe(n)

Returns the number of bytes written to the buffer pointed to by lpMultiByteStr if successful. The number includes the byte for the terminating null character.

If the function succeeds and cbMultiByte is 0, the return value is the required size, in bytes, for the buffer indicated by lpMultiByteStr.

The function returns 0 if it does not succeed. To get extended error information, the application can call GetLastError. GetLastError can return one of the following error codes:

ERROR_INSUFFICIENT_BUFFER ERROR_INVALID_FLAGS ERROR_INVALID_PARAMETER

Beispiel

'Beispielcode...


Betriebsystem

Die Funktion ist unter folgenden Betriebssystemen funktionsfähig:

  • Windows NT 4.0
  • Windows NT 5.0 (2000)
  • Windows XP (ab SP2)
  • Windows Vista (nur x64)


Verwandte Funktionen

Api1 - MultiByteToWideChar
Api2 - Beschreibung


Verweise

'Unicode Functions 'MultiByteToWideChar


[PFLICHT] Quelle(n)