aboutsummaryrefslogtreecommitdiff
path: root/qmidiplayer-desktop
diff options
context:
space:
mode:
authorGravatar Chris Xiong <chirs241097@gmail.com> 2016-05-19 23:54:42 +0800
committerGravatar Chris Xiong <chirs241097@gmail.com> 2016-05-19 23:54:42 +0800
commit78b384662f484e946a6a17c96e6c309df0c039da (patch)
tree70093f05f4e9d02bbc8ddfdd2ddc8bef1cca1751 /qmidiplayer-desktop
parent8ef9703ee2a4b22395935030606fcf69e3acad86 (diff)
downloadQMidiPlayer-78b384662f484e946a6a17c96e6c309df0c039da.tar.xz
Added a sample plugin as a template.
Implemented scanPlugin for Windows.
Diffstat (limited to 'qmidiplayer-desktop')
-rw-r--r--qmidiplayer-desktop/qmpplugin.cpp30
-rw-r--r--qmidiplayer-desktop/qmpplugin.hpp4
2 files changed, 28 insertions, 6 deletions
diff --git a/qmidiplayer-desktop/qmpplugin.cpp b/qmidiplayer-desktop/qmpplugin.cpp
index 22cb696..2117bcf 100644
--- a/qmidiplayer-desktop/qmpplugin.cpp
+++ b/qmidiplayer-desktop/qmpplugin.cpp
@@ -18,6 +18,25 @@ void qmpPluginManager::scanPlugins()
HANDLE dir;
std::vector<std::string> cpluginpaths;
//FindFirstFile, FindNextFile, FindClose
+ LPWIN32_FIND_DATA file;
+ dir=FindFirstFileA(L".\\plugins\\*.dll",file);
+ if(dir!=INVALID_HANDLE_VALUE)
+ {
+ cpluginpaths.push_back(std::string(file->cFileName));
+ while(FindNextFile(dir,file))
+ cpluginpaths.push_back(std::string(file->cFileName));
+ }
+ FindClose(dir);
+ for(unsigned i=0;i<cpluginpaths.size();++i)
+ {
+ HMODULE hso=LoadLibraryA(cpluginpaths[i].c_str());
+ if(!hso){fprintf(stderr,"Error while loading library: %d\n",GetLastError());continue;}
+ FARPROC hndi=GetProcAddress(hso,"qmpPluginGetInterface");
+ if(!hndi){fprintf(stderr,"file %s doesn't seem to be a qmidiplayer plugin.\n",cpluginpaths[i].c_str());continue;}
+ qmpPluginEntry e=(qmpPluginEntry)hndi;
+ qmpPluginIntf* intf=e(pluginAPI);
+ plugins.push_back(qmpPlugin(std::string(intf->pluginGetName()),std::string(intf->pluginGetVersion()),std::string(cpluginpaths[i]),intf));
+ }
}
#else
void qmpPluginManager::scanPlugins()
@@ -46,7 +65,7 @@ void qmpPluginManager::scanPlugins()
void* hso=dlopen(cpluginpaths[i].c_str(),RTLD_LAZY);
if(!hso){fprintf(stderr,"%s\n",dlerror());continue;}
void* hndi=dlsym(hso,"qmpPluginGetInterface");
- if(!hndi)continue;
+ if(!hndi){fprintf(stderr,"file %s doesn't seem to be a qmidiplayer plugin.\n",cpluginpaths[i].c_str());continue;}
qmpPluginEntry e=(qmpPluginEntry)hndi;
qmpPluginIntf* intf=e(pluginAPI);
plugins.push_back(qmpPlugin(std::string(intf->pluginGetName()),std::string(intf->pluginGetVersion()),std::string(cpluginpaths[i]),intf));
@@ -63,7 +82,7 @@ qmpPluginManager::~qmpPluginManager()
{
for(unsigned i=0;i<plugins.size();++i)
{
- if(plugins[i].enabled)plugins[i].interface->deinit();
+ if(plugins[i].initialized)plugins[i].interface->deinit();
delete plugins[i].interface;
}
qmw=NULL;qsw=NULL;delete pluginAPI;
@@ -78,13 +97,16 @@ void qmpPluginManager::initPlugins()
{
if(!plugins[i].enabled)continue;
printf("Loaded plugin: %s\n",plugins[i].path.c_str());
- plugins[i].interface->init();
+ plugins[i].interface->init();plugins[i].initialized=true;
}
}
void qmpPluginManager::deinitPlugins()
{
for(unsigned i=0;i<plugins.size();++i)
- {plugins[i].interface->deinit();plugins[i].enabled=false;}
+ {
+ if(plugins[i].initialized)plugins[i].interface->deinit();
+ plugins[i].enabled=plugins[i].initialized=false;
+ }
}
qmpPluginAPI::~qmpPluginAPI(){}
diff --git a/qmidiplayer-desktop/qmpplugin.hpp b/qmidiplayer-desktop/qmpplugin.hpp
index 836cee2..f689f71 100644
--- a/qmidiplayer-desktop/qmpplugin.hpp
+++ b/qmidiplayer-desktop/qmpplugin.hpp
@@ -8,9 +8,9 @@ struct qmpPlugin
{
std::string name,version,path;
qmpPluginIntf* interface;
- bool enabled;
+ bool enabled,initialized;
qmpPlugin(std::string _n,std::string _v,std::string _p,qmpPluginIntf* _i)
- {name=_n;version=_v;path=_p;interface=_i;enabled=false;}
+ {name=_n;version=_v;path=_p;interface=_i;enabled=initialized=false;}
};
class qmpPluginManager
{