Marshal.PtrToStringUni Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Allocates a managed String and copies all or part of an unmanaged Unicode string into it.
Overloads
PtrToStringUni(IntPtr) |
Allocates a managed String and copies all characters up to the first null character from an unmanaged Unicode string into it. |
PtrToStringUni(IntPtr, Int32) |
Allocates a managed String and copies a specified number of characters from an unmanaged Unicode string into it. |
PtrToStringUni(IntPtr)
- Source:
- Marshal.cs
- Source:
- Marshal.cs
- Source:
- Marshal.cs
Allocates a managed String and copies all characters up to the first null character from an unmanaged Unicode string into it.
public:
static System::String ^ PtrToStringUni(IntPtr ptr);
[System.Security.SecurityCritical]
public static string PtrToStringUni (IntPtr ptr);
public static string? PtrToStringUni (IntPtr ptr);
public static string PtrToStringUni (IntPtr ptr);
[<System.Security.SecurityCritical>]
static member PtrToStringUni : nativeint -> string
static member PtrToStringUni : nativeint -> string
Public Shared Function PtrToStringUni (ptr As IntPtr) As String
Parameters
- ptr
-
IntPtr
nativeint
The address of the first character of the unmanaged string.
Returns
A managed string that holds a copy of the unmanaged string if the value of the ptr
parameter is not null
; otherwise, this method returns null
.
- Attributes
Remarks
PtrToStringUni is useful for custom marshaling or for use when mixing managed and unmanaged code. Because this method creates a copy of the unmanaged string's contents, you must free the original string as appropriate. This method provides the opposite functionality of the Marshal.StringToCoTaskMemUni and Marshal.StringToHGlobalUni methods.
This API reflects the Windows definition of Unicode, which is a UTF-16 2-byte encoding. On many non-Windows platforms, the wchar_t
data-type is 4-bytes, not 2-bytes. Consult your compiler to confirm if wchar_t
can be used or char16_t
should be used instead.
See also
Applies to
PtrToStringUni(IntPtr, Int32)
- Source:
- Marshal.cs
- Source:
- Marshal.cs
- Source:
- Marshal.cs
Allocates a managed String and copies a specified number of characters from an unmanaged Unicode string into it.
public:
static System::String ^ PtrToStringUni(IntPtr ptr, int len);
[System.Security.SecurityCritical]
public static string PtrToStringUni (IntPtr ptr, int len);
public static string PtrToStringUni (IntPtr ptr, int len);
[<System.Security.SecurityCritical>]
static member PtrToStringUni : nativeint * int -> string
static member PtrToStringUni : nativeint * int -> string
Public Shared Function PtrToStringUni (ptr As IntPtr, len As Integer) As String
Parameters
- ptr
-
IntPtr
nativeint
The address of the first character of the unmanaged string.
- len
- Int32
The number of Unicode characters to copy.
Returns
A managed string that holds a copy of the unmanaged string if the value of the ptr
parameter is not null
; otherwise, this method returns null
.
- Attributes
Remarks
PtrToStringUni is useful for custom marshaling or when mixing managed and unmanaged code. Because this method creates a copy of the unmanaged string's contents, you must free the original string as appropriate. This method provides the opposite functionality of the Marshal.StringToCoTaskMemUni and Marshal.StringToHGlobalUni methods.
This API reflects the Windows definition of Unicode, which is a UTF-16 2-byte encoding. On many non-Windows platforms, the wchar_t
data-type is 4-bytes, not 2-bytes. Consult your compiler to confirm if wchar_t
can be used or char16_t
should be used instead.
See also
Applies to
Atsauksmes
https://aka.ms/ContentUserFeedback.
Drīzumā: 2024. gada laikā mēs pakāpeniski pārtrauksim izmantot “GitHub problēmas” kā atsauksmju par saturu mehānismu un aizstāsim to ar jaunu atsauksmju sistēmu. Papildinformāciju skatiet:Iesniegt un skatīt atsauksmes par