Marshal.StringToHGlobalUni(String) Marshal.StringToHGlobalUni(String) Marshal.StringToHGlobalUni(String) Marshal.StringToHGlobalUni(String) Method

Definition

Copies the contents of a managed String into unmanaged memory.

public:
 static IntPtr StringToHGlobalUni(System::String ^ s);
[System.Security.SecurityCritical]
public static IntPtr StringToHGlobalUni (string s);
static member StringToHGlobalUni : string -> nativeint
Public Shared Function StringToHGlobalUni (s As String) As IntPtr

Parameters

s
String String String String

A managed string to be copied.

Returns

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

Exceptions

The method could not allocate enough native heap memory.

The s parameter exceeds the maximum length allowed by the operating system.

Remarks

StringToHGlobalUni 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 FreeHGlobal. This method provides the opposite functionality of Marshal.PtrToStringUni.

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

Security

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

Applies to

See also