Marshal.PtrToStringUni Marshal.PtrToStringUni Marshal.PtrToStringUni Marshal.PtrToStringUni Method

Definition

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

Overloads

PtrToStringUni(IntPtr) PtrToStringUni(IntPtr) PtrToStringUni(IntPtr) 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) PtrToStringUni(IntPtr, Int32) PtrToStringUni(IntPtr, Int32) PtrToStringUni(IntPtr, Int32)

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

PtrToStringUni(IntPtr) PtrToStringUni(IntPtr) PtrToStringUni(IntPtr) 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);
static member PtrToStringUni : nativeint -> string
Public Shared Function PtrToStringUni (ptr As IntPtr) As String
Parameters
ptr
IntPtr IntPtr IntPtr IntPtr

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

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.

Security

SecurityCriticalAttribute
requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code.

See Also

PtrToStringUni(IntPtr, Int32) PtrToStringUni(IntPtr, Int32) PtrToStringUni(IntPtr, Int32) 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);
static member PtrToStringUni : nativeint * int -> string
Public Shared Function PtrToStringUni (ptr As IntPtr, len As Integer) As String
Parameters
ptr
IntPtr IntPtr IntPtr IntPtr

The address of the first character of the unmanaged string.

len
Int32 Int32 Int32 Int32

The number of Unicode characters to copy.

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

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.

Security

SecurityCriticalAttribute
requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code.

See Also

Applies to