Replace ILinkedLibManager.LoadOrNull w/ LoadOrZero
seeaa8fe56ef
and4baefd874
This commit is contained in:
parent
7afa4a2f98
commit
c248ee495a
|
@ -195,9 +195,9 @@ namespace BizHawk.Client.Common
|
|||
private static bool DetectDirectX()
|
||||
{
|
||||
if (OSTailoredCode.IsUnixHost) return false;
|
||||
var p = OSTailoredCode.LinkedLibManager.LoadOrNull("d3dx9_43.dll");
|
||||
if (p == null) return false;
|
||||
OSTailoredCode.LinkedLibManager.FreeByPtr(p.Value);
|
||||
var p = OSTailoredCode.LinkedLibManager.LoadOrZero("d3dx9_43.dll");
|
||||
if (p == IntPtr.Zero) return false;
|
||||
OSTailoredCode.LinkedLibManager.FreeByPtr(p);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -42,19 +42,20 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
// some users won't even have xinput installed. in order to avoid spurious exceptions and possible instability, check for the library first
|
||||
var llManager = OSTailoredCode.LinkedLibManager;
|
||||
var libraryHandle = llManager.LoadOrNull("xinput1_3.dll") ?? llManager.LoadOrNull("xinput1_4.dll");
|
||||
if (libraryHandle != null)
|
||||
var libraryHandle = llManager.LoadOrZero("xinput1_3.dll");
|
||||
if (libraryHandle == IntPtr.Zero) libraryHandle = llManager.LoadOrZero("xinput1_4.dll");
|
||||
if (libraryHandle != IntPtr.Zero)
|
||||
{
|
||||
XInputGetStateExProc = (XInputGetStateExProcDelegate) Marshal.GetDelegateForFunctionPointer(
|
||||
Win32Imports.GetProcAddressOrdinal(libraryHandle.Value, new IntPtr(100)),
|
||||
Win32Imports.GetProcAddressOrdinal(libraryHandle, new IntPtr(100)),
|
||||
typeof(XInputGetStateExProcDelegate)
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
libraryHandle = llManager.LoadOrNull("xinput9_1_0.dll");
|
||||
libraryHandle = llManager.LoadOrZero("xinput9_1_0.dll");
|
||||
}
|
||||
IsAvailable = libraryHandle != null;
|
||||
IsAvailable = libraryHandle != IntPtr.Zero;
|
||||
|
||||
// don't remove this code. it's important to catch errors on systems with broken xinput installs.
|
||||
// (probably, checking for the library was adequate, but let's not get rid of this anyway)
|
||||
|
|
|
@ -32,14 +32,14 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
static void CheckLib(string dllToLoad, string desc)
|
||||
{
|
||||
var p = OSTC.LinkedLibManager.LoadOrNull(dllToLoad);
|
||||
if (p == null)
|
||||
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 for more info. (EmuHawk will now close.)")) box.ShowDialog();
|
||||
Process.GetCurrentProcess().Kill();
|
||||
return;
|
||||
}
|
||||
OSTC.LinkedLibManager.FreeByPtr(p.Value);
|
||||
OSTC.LinkedLibManager.FreeByPtr(p);
|
||||
}
|
||||
CheckLib("vcruntime140.dll", "Microsoft's Universal CRT (MSVC 14.0+ / VS 2015+)");
|
||||
CheckLib("vcruntime140_1.dll", "Microsoft's Universal CRT (MSVC 14.0+ / VS 2015+)");
|
||||
|
|
|
@ -39,7 +39,7 @@ namespace BizHawk.Common
|
|||
/// <exception cref="InvalidOperationException">could not find symbol</exception>
|
||||
IntPtr GetProcAddrOrThrow(IntPtr hModule, string procName);
|
||||
|
||||
IntPtr? LoadOrNull(string dllToLoad);
|
||||
IntPtr LoadOrZero(string dllToLoad);
|
||||
|
||||
/// <exception cref="InvalidOperationException">could not find library</exception>
|
||||
IntPtr LoadOrThrow(string dllToLoad);
|
||||
|
@ -72,14 +72,15 @@ namespace BizHawk.Common
|
|||
throw new InvalidOperationException($"error in {nameof(dlsym)}{(errCharPtr == IntPtr.Zero ? string.Empty : $": {Marshal.PtrToStringAnsi(errCharPtr)}")}");
|
||||
}
|
||||
|
||||
public IntPtr? LoadOrNull(string dllToLoad)
|
||||
public IntPtr LoadOrZero(string dllToLoad) => dlopen(dllToLoad, RTLD_NOW);
|
||||
|
||||
public IntPtr LoadOrThrow(string dllToLoad)
|
||||
{
|
||||
const int RTLD_NOW = 2;
|
||||
var p = dlopen(dllToLoad, RTLD_NOW);
|
||||
return p == IntPtr.Zero ? (IntPtr?) null : p;
|
||||
var ret = LoadOrZero(dllToLoad);
|
||||
return ret != IntPtr.Zero ? ret : throw new InvalidOperationException($"got null pointer from {nameof(dlopen)}, error: {Marshal.PtrToStringAnsi(dlerror())}");
|
||||
}
|
||||
|
||||
public IntPtr LoadOrThrow(string dllToLoad) => LoadOrNull(dllToLoad) ?? throw new InvalidOperationException($"got null pointer from {nameof(dlopen)}, error: {Marshal.PtrToStringAnsi(dlerror())}");
|
||||
private const int RTLD_NOW = 2;
|
||||
}
|
||||
|
||||
private class WindowsLLManager : ILinkedLibManager
|
||||
|
@ -108,13 +109,13 @@ namespace BizHawk.Common
|
|||
return ret != IntPtr.Zero ? ret : throw new InvalidOperationException($"got null pointer from {nameof(GetProcAddress)}, error code: {GetLastError()}");
|
||||
}
|
||||
|
||||
public IntPtr? LoadOrNull(string dllToLoad)
|
||||
{
|
||||
var p = LoadLibrary(dllToLoad);
|
||||
return p == IntPtr.Zero ? (IntPtr?) null : p;
|
||||
}
|
||||
public IntPtr LoadOrZero(string dllToLoad) => LoadLibrary(dllToLoad);
|
||||
|
||||
public IntPtr LoadOrThrow(string dllToLoad) => LoadOrNull(dllToLoad) ?? throw new InvalidOperationException($"got null pointer from {nameof(LoadLibrary)}, error code: {GetLastError()}");
|
||||
public IntPtr LoadOrThrow(string dllToLoad)
|
||||
{
|
||||
var ret = LoadOrZero(dllToLoad);
|
||||
return ret != IntPtr.Zero ? ret : throw new InvalidOperationException($"got null pointer from {nameof(LoadLibrary)}, error code: {GetLastError()}");
|
||||
}
|
||||
}
|
||||
|
||||
public enum DistinctOS : byte
|
||||
|
|
|
@ -93,10 +93,10 @@ namespace BizHawk.Emulation.DiscSystem
|
|||
|
||||
static void CheckLibrary()
|
||||
{
|
||||
var lib = OSTailoredCode.LinkedLibManager.LoadOrNull("mednadisc.dll");
|
||||
_IsLibraryAvailable = lib != null
|
||||
&& OSTailoredCode.LinkedLibManager.GetProcAddrOrZero(lib.Value, "mednadisc_LoadCD") != IntPtr.Zero;
|
||||
if (lib != null) OSTailoredCode.LinkedLibManager.FreeByPtr(lib.Value);
|
||||
var lib = OSTailoredCode.LinkedLibManager.LoadOrZero("mednadisc.dll");
|
||||
_IsLibraryAvailable = lib != IntPtr.Zero
|
||||
&& OSTailoredCode.LinkedLibManager.GetProcAddrOrZero(lib, "mednadisc_LoadCD") != IntPtr.Zero;
|
||||
if (lib != IntPtr.Zero) OSTailoredCode.LinkedLibManager.FreeByPtr(lib);
|
||||
}
|
||||
|
||||
static MednaDisc()
|
||||
|
|
Loading…
Reference in New Issue