Fixed DLL-Import for ImGui.NET

This commit is contained in:
Simon Lübeß
2025-07-17 15:13:21 +02:00
parent f7bcff5337
commit f77b153512
+8 -2
View File
@@ -40,14 +40,20 @@ internal static unsafe partial class ScriptGlue
static ScriptGlue() static ScriptGlue()
{ {
NativeLibrary.SetDllImportResolver(typeof(ScriptGlue).Assembly, ImportResolver); NativeLibrary.SetDllImportResolver(typeof(ScriptGlue).Assembly, ImportResolver);
// TODO: With this we can actually use the official ImGui.NET-Branch in the future!
NativeLibrary.SetDllImportResolver(typeof(ImGui).Assembly, ImportResolver);
} }
private static IntPtr ImportResolver(string libraryName, Assembly assembly, DllImportSearchPath? searchPath) private static IntPtr ImportResolver(string libraryName, Assembly assembly, DllImportSearchPath? searchPath)
{ {
if (libraryName == "__Internal") if (libraryName == "__Internal")
{ {
// Lade die aktuelle exe selbst string? mainModuleFileName = Process.GetCurrentProcess().MainModule?.FileName;
return NativeLibrary.Load(Process.GetCurrentProcess().MainModule.FileName);
if (mainModuleFileName != null)
return NativeLibrary.Load(mainModuleFileName);
throw new DllNotFoundException("Failed to resolve import to current executable: Could not find file name of main module.");
} }
return IntPtr.Zero; return IntPtr.Zero;