add way to obtain error message in ILinkedLibManager, use it to display an error code for init lib checks

This commit is contained in:
CasualPokePlayer 2022-08-29 15:34:44 -07:00
parent 463780a875
commit 06226e78cf
2 changed files with 12 additions and 2 deletions

View File

@ -38,7 +38,7 @@ namespace BizHawk.Client.EmuHawk
var p = OSTC.LinkedLibManager.LoadOrZero(dllToLoad);
if (p == IntPtr.Zero)
{
using (var box = new ExceptionBox($"EmuHawk needs {desc} in order to run! See the readme on GitHub for more info. (EmuHawk will now close.)")) box.ShowDialog();
using (var box = new ExceptionBox($"EmuHawk needs {desc} in order to run! See the readme on GitHub for more info. (EmuHawk will now close.) Internal error message: {OSTC.LinkedLibManager.GetErrorMessage()}")) box.ShowDialog();
Process.GetCurrentProcess().Kill();
return;
}

View File

@ -91,6 +91,8 @@ namespace BizHawk.Common
/// <exception cref="InvalidOperationException">could not find library</exception>
IntPtr LoadOrThrow(string dllToLoad);
string GetErrorMessage();
}
private class UnixMonoLLManager : ILinkedLibManager
@ -128,6 +130,12 @@ namespace BizHawk.Common
return ret != IntPtr.Zero ? ret : throw new InvalidOperationException($"got null pointer from {nameof(dlopen)}, error: {Marshal.PtrToStringAnsi(dlerror())}");
}
public string GetErrorMessage()
{
var errCharPtr = dlerror();
return errCharPtr == IntPtr.Zero ? "No error present" : Marshal.PtrToStringAnsi(errCharPtr);
}
private const int RTLD_NOW = 2;
}
@ -163,7 +171,9 @@ namespace BizHawk.Common
{
var ret = LoadOrZero(dllToLoad);
return ret != IntPtr.Zero ? ret : throw new InvalidOperationException($"got null pointer from {nameof(LoadLibrary)}, error code: {GetLastError()}");
}
}
public string GetErrorMessage() => $"Error Code 0x{GetLastError():X8}";
}
public enum DistinctOS : byte