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

◆ ConvertToNative()

static unsafe IntPtr System.StubHelpers.VBByValStrMarshaler.ConvertToNative ( string strManaged,
bool fBestFit,
bool fThrowOnUnmappableChar,
ref int cch )
inlinestaticpackage

Definition at line 7 of file VBByValStrMarshaler.cs.

8 {
9 if (strManaged == null)
10 {
11 return IntPtr.Zero;
12 }
13 cch = strManaged.Length;
14 int cb = checked(4 + (cch + 1) * Marshal.SystemMaxDBCSCharSize);
15 byte* ptr = (byte*)(void*)Marshal.AllocCoTaskMem(cb);
16 int* ptr2 = (int*)ptr;
17 ptr += 4;
18 if (cch == 0)
19 {
20 *ptr = 0;
21 *ptr2 = 0;
22 }
23 else
24 {
25 int cbLength;
26 byte[] array = AnsiCharMarshaler.DoAnsiConversion(strManaged, fBestFit, fThrowOnUnmappableChar, out cbLength);
27 Buffer.Memmove(ref *ptr, ref MemoryMarshal.GetArrayDataReference(array), (nuint)cbLength);
28 ptr[cbLength] = 0;
29 *ptr2 = cbLength;
30 }
31 return new IntPtr(ptr);
32 }
static IntPtr AllocCoTaskMem(int cb)
Definition Marshal.cs:1702
static readonly int SystemMaxDBCSCharSize
Definition Marshal.cs:19
static unsafe ref byte GetArrayDataReference(Array array)

References System.Runtime.InteropServices.Marshal.AllocCoTaskMem(), System.array, System.StubHelpers.AnsiCharMarshaler.DoAnsiConversion(), System.Runtime.InteropServices.MemoryMarshal.GetArrayDataReference(), System.Buffer.Memmove(), System.Runtime.InteropServices.Marshal.SystemMaxDBCSCharSize, and System.IntPtr.Zero.