RtlUnicodeStringInitEx - NtDoc

Native API online documentation, based on the System Informer (formerly Process Hacker) phnt headers
#ifndef _NTSTRSAFE_H_INCLUDED_
#ifndef NTSTRSAFE_LIB_IMPL
#ifndef NTSTRSAFE_NO_UNICODE_STRING_FUNCTIONS

/*++

  NTSTATUS
  RtlUnicodeStringInitEx(
  _Out_ PUNICODE_STRING DestinationString,
  _In_opt_  NTSTRSAFE_PCWSTR pszSrc              OPTIONAL,
  _In_ DWORD           dwFlags
  );

  Routine Description:

  In addition to functionality provided by RtlUnicodeStringInit, this routine
  includes the flags parameter allows additional controls.

  This function returns an NTSTATUS value.  It returns STATUS_SUCCESS if the
  counted unicode string was successfully initialized from pszSrc. In failure
  cases the unicode string buffer will be set to NULL, and the Length and
  MaximumLength members will be set to zero.

Arguments:

DestinationString - pointer to the counted unicode string to be initialized

pszSrc            - source string which must be null terminated

dwFlags           - controls some details of the initialization:

STRSAFE_IGNORE_NULLS
do not fault on a NULL DestinationString pointer

Return Value:

STATUS_SUCCESS -

failure        -   the operation did not succeed

STATUS_INVALID_PARAMETER

It is strongly recommended to use the NT_SUCCESS() macro to test the
return value of this function.

--*/

_At_(DestinationString->Buffer, _Post_equal_to_(pszSrc))
_At_(DestinationString->Length, _Post_equal_to_(_String_length_(pszSrc) * sizeof(WCHAR)))
_At_(DestinationString->MaximumLength, _Post_equal_to_((_String_length_(pszSrc)+1) * sizeof(WCHAR)))
NTSTRSAFEDDI
RtlUnicodeStringInitEx(
        _Out_ PUNICODE_STRING DestinationString,
        _In_opt_ NTSTRSAFE_PCWSTR pszSrc,
        _In_ DWORD dwFlags)
{
    NTSTATUS status;

    if (dwFlags & (~STRSAFE_UNICODE_STRING_VALID_FLAGS))
    {
        status = STATUS_INVALID_PARAMETER;
    }
    else
    {
        status = RtlUnicodeStringInitWorker(DestinationString,
                pszSrc,
                NTSTRSAFE_UNICODE_STRING_MAX_CCH,
                dwFlags);
    }

    if (!NT_SUCCESS(status) && DestinationString)
    {
        DestinationString->Length = 0;
        DestinationString->MaximumLength = 0;
        DestinationString->Buffer = NULL;
    }

    return status;
}

#endif
#endif
#endif

View code on GitHub
// ntstrsafe.h

NTSTRSAFEDDI RtlUnicodeStringInitEx(
  [out]          PUNICODE_STRING  DestinationString,
  [in, optional] NTSTRSAFE_PCWSTR pszSrc,
  [in]           DWORD            dwFlags
);

View the official Windows Driver Kit DDI reference

NtDoc

No description available.

Windows Driver Kit DDI reference (nf-ntstrsafe-rtlunicodestringinitex)

RtlUnicodeStringInitEx function

Description

The RtlUnicodeStringInitEx function initializes a UNICODE_STRING structure.

Parameters

DestinationString [out]

Optional. A pointer to a UNICODE_STRING structure to be initialized. The pszSrc pointer is copied into the DestinationString parameter's UNICODE_STRING structure. The maximum number of characters in the string that pszSrc points to is NTSTRSAFE_UNICODE_STRING_MAX_CCH. DestinationString can be NULL, but only if STRSAFE_IGNORE_NULLS is set in dwFlags.

pszSrc [in, optional]

Optional. A pointer to a null-terminated string constant. This string pointer will be copied to the Buffer member of the UNICODE_STRING structure pointed to by the DestinationString parameter. This string pointer can be NULL.

dwFlags [in]

The following flag is defined:

STRSAFE_IGNORE_NULLS

If this flag is set, the source pointer can be NULL. RtlUnicodeStringInitEx treats NULL source buffer pointers like empty strings (TEXT("")), which can be copied.

Return value

RtlUnicodeStringInitEx returns one of the following NTSTATUS values.

Return code Description
STATUS_SUCCESS This success status means that source data was present, the string was copied without truncation, and the resultant destination buffer is null-terminated.
STATUS_INVALID_PARAMETER This error status means that the function received an invalid input parameter. For more information, see the following list.

RtlUnicodeStringInitEx returns the STATUS_INVALID_PARAMETER value when one of the following occurs:

For information about how to test NTSTATUS values, see Using NTSTATUS Values.

Remarks

The RtlUnicodeStringInitEx function does the following:

The DestinationString pointer cannot be NULL unless the STRSAFE_IGNORE_NULLS flag is set.

For more information about the safe string functions, see Using Safe String Functions.

See also

RtlUnicodeStringInit

UNICODE_STRING