Exemplo n.º 1
0
            public static DSPPlugin LoadLibrary(string moduleFileName, IntPtr parentWindowHandle)
            {
                DSPPluginImpl plugin = new DSPPluginImpl();

                Debug.WriteLine("Loading DSP Plugin: " + Path.GetFullPath(moduleFileName));

                // LoadLibrary
                IntPtr hModule = NativeMethods.LoadLibrary(Path.GetFullPath(moduleFileName));

                if (hModule == IntPtr.Zero)
                {
                    Debug.WriteLine(" - Failed to LoadLibrary.");
                    return(null);
                }

                // Get address of winampDSPGetHeader2()
                var getHeader = NativeMethods.GetProcAddress <NativeMethods.winampDSPGetHeader2Delegate>(hModule, "winampDSPGetHeader2");

                if (getHeader == null)
                {
                    Debug.WriteLine(" - Failed to GetProcAddress(winampDSPGetHeader2). ");
                    NativeMethods.FreeLibrary(hModule);
                    return(null);
                }

                // Get winampDSPHeaderEx heder from winampDSPGetHeader2()
                IntPtr pHeader = getHeader(parentWindowHandle);

                if (pHeader == IntPtr.Zero)
                {
                    Debug.WriteLine(" - Failed to winampDSPGetHeader2()");
                    NativeMethods.FreeLibrary(hModule);
                    return(null);
                }
                var header = NativeMethods.PtrToStructure <NativeMethods.winampDSPHeaderEx>(pHeader);

                Debug.WriteLine(" + Plug-in: " + header.Description);
                Debug.WriteLine(" + Header version: " + header.DspHeaderVersion);

                // enumrate modules
                List <DSPModule> modules = new List <DSPModule>();
                var GetModule            = NativeMethods.GetDelegateFromFunctionPtr <NativeMethods.GetModuleDelegate>(header.GetModule);

                for (int i = 0; ; i++)
                {
                    IntPtr p = GetModule(i);
                    if (p == IntPtr.Zero)
                    {
                        break;
                    }

                    Marshal.WriteIntPtr(new IntPtr(p.ToInt64() + 4), parentWindowHandle);
                    Marshal.WriteIntPtr(new IntPtr(p.ToInt64() + 8), hModule);
                    var module = DSPModuleImpl.FromModulePtr(p);
                    Debug.WriteLine(" + Module #" + (i + 1) + ": " + module.Description);
                    modules.Add(module);
                }

                plugin.Loaded           = true;
                plugin.ModuleHandle     = hModule;
                plugin.ModulePath       = moduleFileName;
                plugin.DspHeaderVersion = header.DspHeaderVersion;
                plugin.Description      = header.Description;
                plugin.Modules          = modules.AsReadOnly();

                return(plugin);
            }
Exemplo n.º 2
0
 /// <summary>
 /// Load a plugin.
 /// </summary>
 /// <param name="dspPluginFileName"></param>
 /// <param name="parentWindowHandle"></param>
 /// <returns></returns>
 public static DSPPlugin LoadDSPPlugin(string dspPluginFileName, IntPtr parentWindowHandle)
 {
     return(DSPPluginImpl.LoadLibrary(dspPluginFileName, parentWindowHandle));
 }