Marshal.StringToHGlobalUni(String) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
將管理記憶體 String 的內容複製到未管理記憶體。
public:
static IntPtr StringToHGlobalUni(System::String ^ s);
[System.Security.SecurityCritical]
public static IntPtr StringToHGlobalUni(string s);
public static IntPtr StringToHGlobalUni(string? s);
public static IntPtr StringToHGlobalUni(string s);
[<System.Security.SecurityCritical>]
static member StringToHGlobalUni : string -> nativeint
static member StringToHGlobalUni : string -> nativeint
Public Shared Function StringToHGlobalUni (s As String) As IntPtr
參數
- s
- String
一個可管理的字串,要被複製。
傳回
nativeint
在非管理記憶體中,複製 的 s 位址,或若 s 為 null則為 0。
- 屬性
例外狀況
此方法無法分配足夠的原生堆積記憶體。
參數 s 超過作業系統允許的最大長度。
備註
StringToHGlobalUni 適合自訂封組或混合管理與非管理程式碼時使用。 由於此方法分配字串所需的非管理記憶體,故必須透過呼叫 FreeHGlobal來釋放該記憶體。 此方法提供與 相反 Marshal.PtrToStringUni的功能。
此方法複製嵌入的空字元,並包含一個終止的空字元。
此 API 反映了 Windows 對 Unicode 的定義,為 UTF-16 2 位元組編碼。 在許多非Windows平台上,wchar_t 資料型態為 4 位元組,而非 2 位元組。 請諮詢你的編譯器,確認是否 wchar_t 可以使用或 char16_t 應該改用。