MultiByteToWideChar

Aus API-Wiki
Version vom 21. Oktober 2008, 18:38 Uhr von Philipp Stephani (Diskussion | Beiträge) (Einige Fehler korrigiert)
Zur Navigation springenZur Suche springen

Die API-Funktion MultiByteToWideChar konvertiert einen einbyte/mehrbyte-Character-String in einen Wide-Character-Unicode-String.

Declare Function MultiByteToWideChar lib "kernel32.dll" ( _

                ByVal CodePage As Long, _
                ByVal dwFlags As Long, _
                ByRef lpMultiByteStr As Byte, _
                ByVal cchMultiByte As Long, _
                ByVal lpWideCharStr As Long, _
                ByVal cchWideChar As Long) As Long


Parameter

CodePage

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 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_UTF7 As Long = 65000 'UTF-7 code page Private Const CP_UTF8 As Long = 65001 'UTF-8 code page

dwFlags

Es kann eine Kombination aus folgenden Flags verwendet werden

Private Const MB_PRECOMPOSED As Long = &H1 'Always use precomposed characters — that is, characters in

                                                'which a base character and a nonspacing character have a
                                                'single character value. This is the default translation option.
                                                'Cannot be used with MB_COMPOSITE.

Private Const MB_COMPOSITE As Long = &H2 'Always use composite characters — that is, characters in

                                                'which a base character and a nonspacing character have
                                                'different character values. Cannot be used with MB_PRECOMPOSED.

Private Const MB_USEGLYPHCHARS As Long = &H4 'Use glyph characters instead of control characters

Private Const MB_ERR_INVALID_CHARS As Long = &H8 'If the function encounters an invalid input character,

                                                'it fails and Err.LastDllError returns ERROR_NO_UNICODE_TRANSLATION.

lpMultiByteStr

[in] Zeiger auf die 8-Bit-Zeichenfolge, die konvertiert werden soll.

cchMultiByte

[in] Größe, in Bytes, der 8-Bit-Zeichenfolge, der konvertiert werden soll.

lpWideCharStr

[out] Zeiger auf einen Puffer, der den übersetzten UTF-16-String empfängt.

cchWideChar

[in] Größe, in Wide-Characters, des Puffers, der den übersetzten UTF-16-String enthält.

Wenn hier 0 übergeben wird, liefert die Funktion die erforderliche Größe in UTF-16-Codeeinheiten zurück, aber es wird nichts übersetzt.

Rückgabe(n)

Anzahl der UTF-16-Codeeinheiten, die in den Puffer geschrieben wurden, wenn die Funktion erfolgreich war und cchWideChar ist <> 0. Anmerkung: die zurückgegebene Länge enthält ein Null-Terminierungs-Zeichen.

Zero indicates failure. To get extended error information, call GetLastError. Possible values for GetLastError include the following:

ERROR_INSUFFICIENT_BUFFER ERROR_INVALID_FLAGS ERROR_INVALID_PARAMETER ERROR_NO_UNICODE_TRANSLATION

Remarks If lpMultiByteStr and lpWideCharStr pointers are the same, the function fails, and GetLastError returns the value ERROR_INVALID_PARAMETER. The function fails if MB_ERR_INVALID_CHARS is set and it encounters an invalid character in the source string. An invalid character is one that would translate to the default character if MB_ERR_INVALID_CHARS was not set, but is not the default character in the source string, or when a lead byte is found in a string and there is no valid trail byte for DBCS strings. When an invalid character is found, and MB_ERR_INVALID_CHARS is set, the function returns 0 and sets GetLastError with the error ERROR_NO_UNICODE_TRANSLATION.

Beispiel

'Beispielcode...


Betriebssystem

Die Funktion ist unter folgenden Betriebssystemen funktionsfähig:

  • Windows NT 3.1 und später
  • Windows 2000
  • Windows XP
  • Windows Vista


Quellen