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

◆ GetMessage() [22/22]

static unsafe string Interop.Kernel32.GetMessage ( int errorCode,
IntPtr moduleHandle )
inlinestaticpackage

Definition at line 387 of file Interop.cs.

388 {
389 int num = 12800;
390 if (moduleHandle != IntPtr.Zero)
391 {
392 num |= 0x800;
393 }
394 Span<char> span = stackalloc char[256];
395 fixed (char* lpBuffer = span)
396 {
397 int num2 = FormatMessage(num, moduleHandle, (uint)errorCode, 0, lpBuffer, span.Length, IntPtr.Zero);
398 if (num2 > 0)
399 {
400 return GetAndTrimString(span.Slice(0, num2));
401 }
402 }
403 if (Marshal.GetLastWin32Error() == 122)
404 {
405 IntPtr intPtr = default(IntPtr);
406 try
407 {
408 int num3 = FormatMessage(num | 0x100, moduleHandle, (uint)errorCode, 0, &intPtr, 0, IntPtr.Zero);
409 if (num3 > 0)
410 {
411 return GetAndTrimString(new Span<char>((void*)intPtr, num3));
412 }
413 }
414 finally
415 {
416 Marshal.FreeHGlobal(intPtr);
417 }
418 }
419 return $"Unknown error (0x{errorCode:x})";
420 }
static unsafe int FormatMessage(int dwFlags, IntPtr lpSource, uint dwMessageId, int dwLanguageId, void *lpBuffer, int nSize, IntPtr arguments)
static string GetAndTrimString(Span< char > buffer)
Definition Interop.cs:153
static void FreeHGlobal(IntPtr hglobal)
Definition Marshal.cs:1680
static readonly IntPtr Zero
Definition IntPtr.cs:18
Span< T > Slice(int start)
Definition Span.cs:271
int Length
Definition Span.cs:70

References Interop.Kernel32.FormatMessage(), System.Runtime.InteropServices.Marshal.FreeHGlobal(), Interop.Kernel32.GetAndTrimString(), System.Runtime.InteropServices.Marshal.GetLastWin32Error(), System.Span< T >.Length, System.Span< T >.Slice(), and System.IntPtr.Zero.