static IntPtr Load_ios_internal() { // TODO err check this var dll = NativeLib_dlopen.dlopen(null, NativeLib_dlopen.RTLD_NOW); return(dll); }
static bool TryLoad( string name, Loader plat, Action <string> log, out IntPtr h ) { try { if (plat == Loader.win) { log($"win TryLoad: {name}"); var ptr = NativeLib_Win.LoadLibrary(name); if (ptr != IntPtr.Zero) { log($"LoadLibrary gave: {ptr}"); h = ptr; return(true); } else { var err = Marshal.GetLastWin32Error(); // NOT HERE: log($"error code: {err}"); throw new System.ComponentModel.Win32Exception(); } } else if (plat == Loader.dlopen) { log($"dlopen TryLoad: {name}"); var ptr = NativeLib_dlopen.dlopen(name, NativeLib_dlopen.RTLD_NOW); log($"dlopen gave: {ptr}"); if (ptr != IntPtr.Zero) { h = ptr; return(true); } else { // TODO log errno? h = IntPtr.Zero; return(false); } } else { throw new NotImplementedException(); } } catch (NotImplementedException) { throw; } catch (Exception e) { log($"thrown: {e}"); h = IntPtr.Zero; return(false); } }
static IntPtr MyGetExport(IntPtr handle, string name) { var plat = WhichLoader(); if (plat == Loader.win) { return(NativeLib_Win.GetProcAddress(handle, name)); } else if (plat == Loader.dlopen) { return(NativeLib_dlopen.dlsym(handle, name)); } else { throw new NotImplementedException(); } }
public static void Free(IntPtr handle) { var plat = WhichLoader(); if (plat == Loader.win) { NativeLib_Win.FreeLibrary(handle); } else if (plat == Loader.dlopen) { NativeLib_dlopen.dlclose(handle); } else { throw new NotImplementedException(); } }