Bewerken

Delen via


Marshal.StringToCoTaskMemUTF8(String) Method

Definition

Copies the contents of a managed String to a block of memory allocated from the unmanaged COM task allocator.

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

Parameters

s
String

A managed string to be copied.

Returns

IntPtr

nativeint

An integer representing a pointer to the block of memory allocated for the string, or 0 if s is null.

Attributes

Exceptions

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

There is insufficient memory available.

Remarks

StringToCoTaskMemUTF8 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 including a null terminator, always free the memory by calling Marshal.FreeCoTaskMem. This method provides the opposite functionality of Marshal.PtrToStringUTF8. The characters of the string are copied as UTF-8 characters.

Applies to

See also