CSharp___DllImport.DllImportCaller.lookupDll C# (CSharp) Method

lookupDll() public static method

public static lookupDll ( string dll ) : IntPtr
dll string
return System.IntPtr
        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;
            }
        }

Usage Example

Example #1
0
        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();
        }