System.Runtime.InteropServices.Marshal.StringToHGlobalAuto Method

Copies the contents of a managed string into unmanaged memory, converting into ANSI format if required.

Syntax

public static IntPtr StringToHGlobalAuto (string s)

Parameters

s
A managed string to be copied.

Returns

The address, in unmanaged memory, to where the string was copied, or 0 if s is null.

Remarks

Marshal.StringToHGlobalAuto(string) is useful for custom marshaling or for use when mixing managed and unmanaged code. Because this method allocates the unmanaged memory required for a string, always free the memory by calling Marshal.FreeHGlobal(IntPtr). This method provides the opposite functionality of Marshal.PtrToStringAuto(IntPtr, int).

This method copies embedded null characters, and includes a terminating null character.

Requirements

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