System.Runtime.InteropServices.Marshal.PtrToStringUni Method

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

Syntax

public static string PtrToStringUni (IntPtr ptr)

Parameters

ptr
The address of the first character of the unmanaged string.

Returns

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.

Remarks

Marshal.PtrToStringUni(IntPtr, int) 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(string) and Marshal.StringToHGlobalUni(string) methods.

Requirements

Namespace: System.Runtime.InteropServices
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0