Marshal.PtrToStringAuto 方法

定义

分配托管 String,并向其复制所有或部分非托管字符串。

重载

PtrToStringAuto(IntPtr)

分配托管 String,并从非托管内存中存储的字符串向其复制第一个空字符之前的所有字符。

PtrToStringAuto(IntPtr, Int32)

分配托管 String,并从存储在非托管内存中的字符串向其复制指定数目的字符。

PtrToStringAuto(IntPtr)

Source:
Marshal.Unix.cs
Source:
Marshal.Unix.cs
Source:
Marshal.Unix.cs

分配托管 String,并从非托管内存中存储的字符串向其复制第一个空字符之前的所有字符。

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

参数

ptr
IntPtr

nativeint

对于 Unicode 平台,表示第一个 Unicode 字符的地址。

- 或 -

对于 ANSI 平台,表示第一个 ANSI 字符的地址。

返回

如果 ptr 参数的值不是 null;则为具有非托管字符串副本的托管字符串;否则此方法将返回 null

属性

注解

如果当前平台为 Unicode,则每个 ANSI 字符将扩大为 Unicode 字符,此方法调用 PtrToStringUni。 否则,此方法调用 PtrToStringAnsi

PtrToStringAuto 对于自定义封送处理或混合托管和非托管代码时非常有用。 由于此方法创建非托管字符串内容的副本,因此必须根据需要释放原始字符串。 PtrToStringAuto提供 和 Marshal.StringToHGlobalAuto 方法的Marshal.StringToCoTaskMemAuto相反功能。

另请参阅

适用于

PtrToStringAuto(IntPtr, Int32)

Source:
Marshal.Unix.cs
Source:
Marshal.Unix.cs
Source:
Marshal.Unix.cs

分配托管 String,并从存储在非托管内存中的字符串向其复制指定数目的字符。

public:
 static System::String ^ PtrToStringAuto(IntPtr ptr, int len);
public static string? PtrToStringAuto (IntPtr ptr, int len);
public static string PtrToStringAuto (IntPtr ptr, int len);
[System.Security.SecurityCritical]
public static string PtrToStringAuto (IntPtr ptr, int len);
static member PtrToStringAuto : nativeint * int -> string
[<System.Security.SecurityCritical>]
static member PtrToStringAuto : nativeint * int -> string
Public Shared Function PtrToStringAuto (ptr As IntPtr, len As Integer) As String

参数

ptr
IntPtr

nativeint

对于 Unicode 平台,表示第一个 Unicode 字符的地址。

- 或 -

对于 ANSI 平台,表示第一个 ANSI 字符的地址。

len
Int32

要复制的字符数。

返回

如果 ptr 参数的值不是 null;则为包含本机字符串副本的托管字符串;否则此,方法将返回 null

属性

例外

len 小于零。

注解

在 Unicode 平台上,此方法调用 PtrToStringUni;在 ANSI 平台上,它调用 PtrToStringAnsi。 在调用这些方法之前,不会执行任何转换。

PtrToStringAuto 对于自定义封送处理或混合托管和非托管代码时非常有用。 由于此方法创建非托管字符串内容的副本,因此必须根据需要释放原始字符串。 PtrToStringAuto提供 和 Marshal.StringToHGlobalAutoMarshal.StringToCoTaskMemAuto相反功能。

另请参阅

适用于