RtlUnicodeToMultiByteSize - NtDoc

Native API online documentation, based on the System Informer (formerly Process Hacker) phnt headers
#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
    );

#endif

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

NtDoc

This function is documented in Windows Driver Kit.

Windows Driver Kit DDI reference (nf-ntifs-rtlunicodetomultibytesize)

RtlUnicodeToMultiByteSize function

Description

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).

Parameters

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.

Return value

RtlUnicodeToMultiByteSize returns STATUS_SUCCESS.

Remarks

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.

See also

RtlMultiByteToUnicodeSize

RtlUnicodeToMultiByteN

RtlUpcaseUnicodeToMultiByteN


Win32 API reference (nf-winternl-rtlunicodetomultibytesize)

RtlUnicodeToMultiByteSize function

Description

Determines how many bytes are needed to represent a Unicode string as an ANSI string.

Parameters

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 value

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.

Remarks

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.