Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ StringToCoTaskMemUTF8()

static unsafe IntPtr System.Runtime.InteropServices.Marshal.StringToCoTaskMemUTF8 ( string? s)
inlinestatic

Definition at line 1344 of file Marshal.cs.

1345 {
1346 if (s == null)
1347 {
1348 return IntPtr.Zero;
1349 }
1350 int maxByteCount = Encoding.UTF8.GetMaxByteCount(s.Length);
1351 IntPtr intPtr = AllocCoTaskMem(maxByteCount + 1);
1352 byte* ptr = (byte*)(void*)intPtr;
1353 int bytes;
1354 fixed (char* chars = s)
1355 {
1356 bytes = Encoding.UTF8.GetBytes(chars, s.Length, ptr, maxByteCount);
1357 }
1358 ptr[bytes] = 0;
1359 return intPtr;
1360 }
static IntPtr AllocCoTaskMem(int cb)
Definition Marshal.cs:1702
static Encoding UTF8
Definition Encoding.cs:526

References System.Runtime.InteropServices.Marshal.AllocCoTaskMem(), System.bytes, System.chars, System.s, System.Text.Encoding.UTF8, and System.IntPtr.Zero.