Marshal.PtrToStringUni Method

Definition

Allocates a managed String and copies all or part of an unmanaged Unicode string into it.

Overloads

PtrToStringUni(IntPtr)

Allocates a managed String and copies all characters up to the first null character from an unmanaged Unicode string into it.

PtrToStringUni(IntPtr, Int32)

Allocates a managed String and copies a specified number of characters from an unmanaged Unicode string into it.

PtrToStringUni(IntPtr)

Allocates a managed String and copies all characters up to the first null character from an unmanaged Unicode string into it.

public:
 static System::String ^ PtrToStringUni(IntPtr ptr);
[System.Security.SecurityCritical]
public static string PtrToStringUni (IntPtr ptr);
public static string PtrToStringUni (IntPtr ptr);
static member PtrToStringUni : nativeint -> string
Public Shared Function PtrToStringUni (ptr As IntPtr) As String

Parameters

ptr
IntPtr

The address of the first character of the unmanaged string.

Returns

String

A managed string that holds a copy of the unmanaged string if the value of the ptr parameter is not null; otherwise, this method returns null.

Attributes

Remarks

PtrToStringUni is useful for custom marshaling or for use when mixing managed and unmanaged code. Because this method creates a copy of the unmanaged string's contents, you must free the original string as appropriate. This method provides the opposite functionality of the Marshal.StringToCoTaskMemUni and Marshal.StringToHGlobalUni methods.

See also

PtrToStringUni(IntPtr, Int32)

Allocates a managed String and copies a specified number of characters from an unmanaged Unicode string into it.

public:
 static System::String ^ PtrToStringUni(IntPtr ptr, int len);
[System.Security.SecurityCritical]
public static string PtrToStringUni (IntPtr ptr, int len);
public static string PtrToStringUni (IntPtr ptr, int len);
static member PtrToStringUni : nativeint * int -> string
Public Shared Function PtrToStringUni (ptr As IntPtr, len As Integer) As String

Parameters

ptr
IntPtr

The address of the first character of the unmanaged string.

len
Int32

The number of Unicode characters to copy.

Returns

String

A managed string that holds a copy of the unmanaged string if the value of the ptr parameter is not null; otherwise, this method returns null.

Attributes

Remarks

PtrToStringUni is useful for custom marshaling or when mixing managed and unmanaged code. Because this method creates a copy of the unmanaged string's contents, you must free the original string as appropriate. This method provides the opposite functionality of the Marshal.StringToCoTaskMemUni and Marshal.StringToHGlobalUni methods.

See also

Applies to