private static double GetFreeMemory() { IntPtr module = FunctionLoader.LoadLibrary("Win32Dll1.dll"); if (module == IntPtr.Zero) // error handling { return(0); } // get a "pointer" to the method IntPtr method = FunctionLoader.GetProcAddress(module, "GetFreeMemory"); if (method == IntPtr.Zero) // error handling { FunctionLoader.FreeLibrary(module); // unload library return(0); } // convert "pointer" to delegate DoubleVoidFunc f = (DoubleVoidFunc)Marshal.GetDelegateForFunctionPointer(method, typeof(DoubleVoidFunc)); // use function return(f()); }