/// <summary>Creates a wrapper for the given function of the given module. /// <para>Since EFL 1.23.</para> /// </summary> /// <param name="module">The module wrapper containing the function.</param> /// <param name="functionName">The name of the function to search for.</param> internal FunctionWrapper(NativeModule module, string functionName) { this.module = module; loadResult = new Lazy <FunctionLoadResult <T> > (() => { return(LazyInitialization(module, functionName)); }); }
/// <summary>Loads a function pointer from the given module. /// <para>Since EFL 1.23.</para> /// </summary> /// <param name="moduleName">The name of the module containing the function.</param> /// <param name="functionName">The name of the function to search for.</param> /// <returns>A function pointer that can be used with delegates.</returns> internal static IntPtr LoadFunctionPointer(string moduleName, string functionName) { IntPtr module = NativeModule.LoadLibrary(moduleName); Eina.Log.Debug($"searching {module} for {functionName}"); var s = FunctionInterop.dlsym(module, functionName); Eina.Log.Debug($"searching {module} for{functionName}, result {s}"); return(s); }
///<summary>Loads a function pointer from the given module.</summary> ///<param name="moduleName">The name of the module containing the function.</param> ///<param name="functionName">The name of the function to search for.</param> ///<returns>A function pointer that can be used with delegates.</returns> public static IntPtr LoadFunctionPointer(string moduleName, string functionName) { NativeModule module = new NativeModule(moduleName); Eina.Log.Debug($"searching {module.Module} for {functionName}"); var s = FunctionInterop.dlsym(module.Module, functionName); Eina.Log.Debug($"searching {module.Module} for{functionName}, result {s}"); return(s); }
private NativeModule module; // so it doesn't get unloaded #pragma warning restore 0414 private static FunctionLoadResult <T> LazyInitialization(NativeModule module, string functionName) { if (module.Module == IntPtr.Zero) { return(new FunctionLoadResult <T>(FunctionLoadResultKind.LibraryNotFound)); } else { IntPtr funcptr = FunctionInterop.LoadFunctionPointer(module.Module, functionName); if (funcptr == IntPtr.Zero) { return(new FunctionLoadResult <T>(FunctionLoadResultKind.FunctionNotFound)); } else { return(new FunctionLoadResult <T>(Marshal.GetDelegateForFunctionPointer <T>(funcptr))); } } }