Marshal.PtrToStringUTF8 方法

定义

重载

名称 说明
PtrToStringUTF8(IntPtr)

分配托管 String 字符,并将非托管 UTF-8 字符串中的所有字符复制到其中。

PtrToStringUTF8(IntPtr, Int32)

分配托管 String 的字节,并将非托管 UTF8 字符串中的指定字节数复制到其中。

PtrToStringUTF8(IntPtr)

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

分配托管 String 字符,并将非托管 UTF-8 字符串中的所有字符复制到其中。

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

参数

ptr
IntPtr

nativeint

非托管字符串的第一个字符的地址。

返回

如果参数的值不是ptr,则保存非托管字符串的副本的null托管字符串;否则,此方法返回null

属性

注解

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

另请参阅

适用于

PtrToStringUTF8(IntPtr, Int32)

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

分配托管 String 的字节,并将非托管 UTF8 字符串中的指定字节数复制到其中。

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

参数

ptr
IntPtr

nativeint

非托管字符串的第一个字符的地址。

byteLen
Int32

要复制的字节数。

返回

如果参数的值不是ptr,则保存非托管字符串的副本的null托管字符串;否则,此方法返回null

属性

注解

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

另请参阅

适用于