Copies the contents of a managed string into unmanaged memory, converting into ANSI format if required.
![]()
The address, in unmanaged memory, to where the string was copied, or 0 if s is null.
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.