#ifndef _NTRTL_H
/**
* The RtlUnicodeToMultiByteSize routine determines the number of bytes that are required to store the multibyte translation for the specified Unicode string.
* The translation is assumed to use the current system ANSI code page (ACP). The source string is not necessarily from a multibyte character set.
*
* \param BytesInMultiByteString Pointer to a caller-allocated variable that receives the number of bytes required to store the translated string.
* \param UnicodeString Pointer to the Unicode string for which the multibyte length is to be calculated.
* \param BytesInUnicodeString Length, in bytes, of the source string.
* \return NTSTATUS Successful or errant status.
* \sa https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/ntifs/nf-ntifs-rtlunicodetomultibytesize
*/
NTSYSAPI
NTSTATUS
NTAPI
RtlUnicodeToMultiByteSize(
_Out_ PULONG BytesInMultiByteString,
_In_reads_bytes_(BytesInUnicodeString) PCWCH UnicodeString,
_In_ ULONG BytesInUnicodeString
);
View code on GitHub
// ntifs.h
NTSYSAPI NTSTATUS RtlUnicodeToMultiByteSize(
[out] PULONG BytesInMultiByteString,
[in] PCWCH UnicodeString,
[in] ULONG BytesInUnicodeString
);
View the official Windows Driver Kit DDI reference
// winternl.h
NTSTATUS RtlUnicodeToMultiByteSize(
[out] PULONG BytesInMultiByteString,
[in] PWCH UnicodeString,
[in] ULONG BytesInUnicodeString
);
View the official Win32 API reference
This function is documented in Windows Driver Kit.
The RtlUnicodeToMultiByteSize routine determines the number of bytes that are required to store the multibyte translation for the specified Unicode string. The translation is assumed to use the current system ANSI code page (ACP).
BytesInMultiByteString
[out]Pointer to a caller-allocated variable that receives the number of bytes required to store the translated string.
UnicodeString
[in]Pointer to the Unicode string for which the multibyte length is to be calculated.
BytesInUnicodeString
[in]Length, in bytes, of the source string.
RtlUnicodeToMultiByteSize returns STATUS_SUCCESS.
RtlUnicodeToMultiByteSize can be called to determine how much memory to allocate, or possibly the value to specify for MaxBytesInMultiByteString, before translating a Unicode string to ANSI with RtlUnicodeToMultiByteN or RtlUpcaseUnicodeToMultiByteN. The returned value does not include space for a NULL terminator for the ANSI string.
Like RtlUnicodeToMultiByteN, RtlUnicodeToMultiByteSize supports only precomposed Unicode characters that are mapped to the current system ANSI code page installed at system boot.
For information about other string-handling routines, see Run-Time Library (RTL) Routines.
Determines how many bytes are needed to represent a Unicode string as an ANSI string.
BytesInMultiByteString
[out]Returns the number of bytes for the ANSI equivalent of the Unicode string pointed to by UnicodeString. This number does not include the terminating NULL character.
UnicodeString
[in]The Unicode source string for which the ANSI length is calculated.
BytesInUnicodeString
[in]The number of bytes in the string pointed to by UnicodeString.
Return code | Description |
---|---|
STATUS_SUCCESS | The count was successful. The various NTSTATUS values are defined in NTSTATUS.H, which is distributed with the Windows DDK. |
It is recommended that you use WideCharToMultiByte instead of RtlUnicodeToMultiByteSize. When its cbMultiByte parameter is set to zero, the WideCharToMultiByte function returns the number of bytes required for the buffer.