Example #1
0
        internal static T LookupInternalFunction <T> (string name) where T : class
        {
            IntPtr rv;

            if (runtime_library == IntPtr.Zero)
            {
                runtime_library = new IntPtr(-2 /* RTLD_DEFAULT */);
                rv = Dlfcn.dlsym(runtime_library, name);
                if (rv == IntPtr.Zero)
                {
                    runtime_library = Dlfcn.dlopen("libxammac.dylib", 0);
                    if (runtime_library == IntPtr.Zero)
                    {
                        runtime_library = Dlfcn.dlopen(Path.Combine(Path.GetDirectoryName(typeof(NSApplication).Assembly.Location), "libxammac.dylib"), 0);
                    }
                    if (runtime_library == IntPtr.Zero)
                    {
                        throw new DllNotFoundException("Could not find the runtime library libxammac.dylib");
                    }
                    rv = Dlfcn.dlsym(runtime_library, name);
                }
            }
            else
            {
                rv = Dlfcn.dlsym(runtime_library, name);
            }
            if (rv == IntPtr.Zero)
            {
                throw new EntryPointNotFoundException(string.Format("Could not find the runtime method '{0}'", name));
            }
            return((T)(object)Marshal.GetDelegateForFunctionPointer(rv, typeof(T)));
        }
Example #2
0
 public static unsafe IntPtr CachePointer(IntPtr handle, string constant, IntPtr *storage)
 {
     if (*storage == IntPtr.Zero)
     {
         *storage = Dlfcn.GetIntPtr(handle, constant);
     }
     return(*storage);
 }