Bewerken

Share via


Marshal.StringToCoTaskMemAnsi(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 StringToCoTaskMemAnsi(System::String ^ s);
[System.Security.SecurityCritical]
public static IntPtr StringToCoTaskMemAnsi (string s);
public static IntPtr StringToCoTaskMemAnsi (string? s);
public static IntPtr StringToCoTaskMemAnsi (string s);
[<System.Security.SecurityCritical>]
static member StringToCoTaskMemAnsi : string -> nativeint
static member StringToCoTaskMemAnsi : string -> nativeint
Public Shared Function StringToCoTaskMemAnsi (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

There is insufficient memory available.

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

Remarks

StringToCoTaskMemAnsi is useful for custom marshaling or when mixing managed and unmanaged code. Because this method allocates the unmanaged memory required for a string, always free the memory by calling FreeCoTaskMem. This method provides the opposite functionality of Marshal.PtrToStringAnsi. The characters of the string are copied as ANSI characters.

Applies to

See also