Exemplo n.º 1
0
        public LibRetro(string modulename)
        {
            // like many other emu cores, libretros are in general single instance, so we track some things
            lock (AttachedCores)
            {
                IntPtr newmodule = Win32.LoadLibrary(modulename);
                if (newmodule == IntPtr.Zero)
                {
                    throw new Exception(string.Format("LoadLibrary(\"{0}\") returned NULL", modulename));
                }

                if (AttachedCores.ContainsKey(newmodule))
                {
                    // this core is already loaded, so we must detatch the old instance
                    LibRetro martyr = AttachedCores[newmodule];
                    martyr.retro_deinit();
                    martyr.ClearAllEntryPoints();
                    martyr.hModule = IntPtr.Zero;
                    Win32.FreeLibrary(newmodule);                     // decrease ref count by 1
                }
                AttachedCores[newmodule] = this;
                hModule = newmodule;
                if (!ConnectAllEntryPoints())
                {
                    ClearAllEntryPoints();
                    Win32.FreeLibrary(hModule);
                    hModule = IntPtr.Zero;
                    throw new Exception("ConnectAllEntryPoints() failed.  The console may contain more details.");
                }
            }
        }