Windows Driver Kit: Kernel-Mode Driver Architecture
RtlUnicodeStringCopyString

The RtlUnicodeStringCopyString function copies a string into a UNICODE_STRING structure.

NTSTATUS
  RtlUnicodeStringCopyString(
    OUT PUNICODE_STRING  DestinationString,
    IN LPCTSTR  pszSrc
    );

Parameters

DestinationString
A pointer to a UNICODE_STRING structure that receives the copied string. The string that the pszSrc parameter points to (excluding the terminating NULL) is copied into the buffer that the DestinationString parameter's UNICODE_STRING structure points to. The maximum number of bytes in the string is NTSTRSAFE_UNICODE_STRING_MAX_CCH * sizeof(WCHAR).
pszSrc
A pointer to a NULL-terminated string. This string will be copied into the buffer that the DestinationString parameter's UNICODE_STRING structure points to.

Return Value

RtlUnicodeStringCopytString returns one of the following NTSTATUS values.

Return valueMeaning
STATUS_SUCCESSThis success status means that source data was present, the string was copied without truncation, and the resultant destination buffer is null-terminated.
STATUS_BUFFER_OVERFLOWThis warning status means that the copy operation did not complete because of insufficient buffer space. The destination buffer contains a truncated, null-terminated version of the intended result.
STATUS_INVALID_PARAMETERThis error status means that the function received an invalid input parameter. For more information, see the following list.

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

  • The contents of the UNICODE_STRING structure are invalid.
  • The destination buffer is already full.
  • A buffer pointer is NULL.
  • The destination buffer's length is zero, but a nonzero length source string is present.

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

Comments

The RtlUnicodeStringCopytString function uses the destination buffer's size to ensure that the concatenation operation does not write past the end of the buffer. The function does not terminate the resultant string with a NULL character.

If the source and destination strings overlap, the behavior of the function is undefined.

The pszSrc and DestinationString pointers cannot be NULL. If you need to handle NULL pointer values, use the RtlUnicodeStringCopyStringEx function.

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

Requirements

IRQL: PASSIVE_LEVEL

Headers: Declared in Ntstrsafe.h. Include Ntstrsafe.h. Link to Ntstrsafe.lib.

See Also

RtlUnicodeStringCopyStringEx, UNICODE_STRING


Send feedback on this topic
Built on October 01, 2009
Page view tracker