public static IntPtr lookupDll(string dll) { IntPtr ptr; if (dllPtrs.TryGetValue(dll, out ptr)) //call { return ptr; } else { int call = lib.LoadLibrary7(dll, out ptr); dllPtrs.Add(dll, ptr); return ptr; } }
public static int PtrForFunc(string dll, string method) { IntPtr dllLook; if ((dllLook = DllImportCaller.lookupDll(dll)) != IntPtr.Zero) { IntPtr methodLookup; if ((methodLookup = DllImportCaller.lookupMethod(dllLook, method)) != IntPtr.Zero) { return(methodLookup.ToInt32()); //EXECUTE / OK } else { DllImportCaller.lib.FreeLibrary7(dllLook); throw new Exception("Could not find Method (Dll found)"); } } else { throw new Exception("Could not find dll (" + dll + ")"); } throw new InvalidOperationException(); }