System.Runtime.InteropServices.Marshal.PtrToStringAnsi Method

Copies all characters up to the first null character from an unmanaged ANSI string to a managed string, and widens each ANSI character to Unicode.

Syntax

public static string PtrToStringAnsi (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 ANSI string. If ptr is null, the method returns a null string.

Remarks

Marshal.PtrToStringAnsi(IntPtr) 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.StringToCoTaskMemAnsi(string) and Marshal.StringToHGlobalAnsi(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