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

◆ ConvertToNative()

static unsafe IntPtr System.StubHelpers.CSTRMarshaler.ConvertToNative ( int flags,
string strManaged,
IntPtr pNativeBuffer )
inlinestaticpackage

Definition at line 7 of file CSTRMarshaler.cs.

8 {
9 if (strManaged == null)
10 {
11 return IntPtr.Zero;
12 }
13 byte* ptr = (byte*)(void*)pNativeBuffer;
14 int num;
15 if (ptr != null || Marshal.SystemMaxDBCSCharSize == 1)
16 {
17 num = checked((strManaged.Length + 1) * Marshal.SystemMaxDBCSCharSize + 1);
18 bool flag = false;
19 if (ptr == null)
20 {
21 ptr = (byte*)(void*)Marshal.AllocCoTaskMem(num);
22 flag = true;
23 }
24 try
25 {
26 num = Marshal.StringToAnsiString(strManaged, ptr, num, (flags & 0xFF) != 0, flags >> 8 != 0);
27 }
28 catch (Exception) when (flag)
29 {
30 Marshal.FreeCoTaskMem((IntPtr)ptr);
31 throw;
32 }
33 }
34 else if (strManaged.Length == 0)
35 {
36 num = 0;
37 ptr = (byte*)(void*)Marshal.AllocCoTaskMem(2);
38 }
39 else
40 {
41 byte[] array = AnsiCharMarshaler.DoAnsiConversion(strManaged, (flags & 0xFF) != 0, flags >> 8 != 0, out num);
42 ptr = (byte*)(void*)Marshal.AllocCoTaskMem(num + 2);
43 Buffer.Memmove(ref *ptr, ref MemoryMarshal.GetArrayDataReference(array), (nuint)num);
44 }
45 ptr[num] = 0;
46 ptr[num + 1] = 0;
47 return (IntPtr)ptr;
48 }
static unsafe int StringToAnsiString(string s, byte *buffer, int bufferLength, bool bestFit=false, bool throwOnUnmappableChar=false)
Definition Marshal.cs:1608
static void FreeCoTaskMem(IntPtr ptr)
Definition Marshal.cs:1712
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.Marshal.FreeCoTaskMem(), System.Runtime.InteropServices.MemoryMarshal.GetArrayDataReference(), System.Buffer.Memmove(), System.Runtime.InteropServices.Marshal.StringToAnsiString(), System.Runtime.InteropServices.Marshal.SystemMaxDBCSCharSize, and System.IntPtr.Zero.

Referenced by System.StubHelpers.AsAnyMarshaler.ConvertStringToNative().