RtlInitUnicodeStringEx - NtDoc

Native API online documentation, based on the System Informer (formerly Process Hacker) phnt headers
#ifndef _NTRTL_H
/**
 * The RtlInitUnicodeStringEx routine initializes a counted Unicode string and validates the length of the source string.
 *
 * \param DestinationString A pointer to the UNICODE_STRING structure to initialize.
 * \param SourceString An optional pointer to a null-terminated Unicode string used to initialize the counted string.
 * \return NTSTATUS Successful or errant status.
 * \sa https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/ntifs/nf-ntifs-rtlinitunicodestringex
 * \remarks Accepts at most 32766 WCHARs excluding the terminator. NULL succeeds with both lengths zero. An overlong source returns STATUS_NAME_TOO_LONG with Length and MaximumLength zero and Buffer still pointing to the source. No storage is allocated.
 */
#ifndef PHNT_NO_INLINE_INIT_STRING

FORCEINLINE
NTSTATUS
NTAPI_INLINE
RtlInitUnicodeStringEx(
    _Out_ PUNICODE_STRING DestinationString,
    _In_opt_z_ PCWSTR SourceString
    )
{
    SIZE_T stringLength;

    DestinationString->Length = 0;
    DestinationString->MaximumLength = 0;
    DestinationString->Buffer = (PWCH)SourceString;

    if (!SourceString)
        return STATUS_SUCCESS;

    stringLength = wcslen(SourceString);

    if (stringLength <= UNICODE_STRING_MAX_CHARS - 1)
    {
        DestinationString->Length = (USHORT)stringLength * sizeof(WCHAR);
        DestinationString->MaximumLength = DestinationString->Length + sizeof(UNICODE_NULL);
        return STATUS_SUCCESS;
    }

    return STATUS_NAME_TOO_LONG;
}

#endif
#endif

View code on GitHub
#ifndef _NTRTL_H
/**
 * The RtlInitUnicodeStringEx routine initializes a counted Unicode string and validates the length of the source string.
 *
 * \param DestinationString A pointer to the UNICODE_STRING structure to initialize.
 * \param SourceString An optional pointer to a null-terminated Unicode string used to initialize the counted string.
 * \return NTSTATUS Successful or errant status.
 * \sa https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/ntifs/nf-ntifs-rtlinitunicodestringex
 * \remarks Accepts at most 32766 WCHARs excluding the terminator. NULL succeeds with both lengths zero. An overlong source returns STATUS_NAME_TOO_LONG with Length and MaximumLength zero and Buffer still pointing to the source. No storage is allocated.
 */
#ifndef PHNT_NO_INLINE_INIT_STRING
// ...
#else

NTSYSAPI
NTSTATUS
NTAPI
RtlInitUnicodeStringEx(
    _Out_ PUNICODE_STRING DestinationString,
    _In_opt_z_ PCWSTR SourceString
    );

#endif
#endif

View code on GitHub

NtDoc

No description available.