35 |
# error "Configuration macro CONFIG_PLUGIN_DIR not defined!" |
# error "Configuration macro CONFIG_PLUGIN_DIR not defined!" |
36 |
#endif // CONFIG_PLUGIN_DIR |
#endif // CONFIG_PLUGIN_DIR |
37 |
|
|
38 |
|
#if defined(WIN32) |
39 |
|
typedef void* (*InnerFactoryRegisterFunction)(void); |
40 |
|
#endif |
41 |
|
|
42 |
namespace LinuxSampler { |
namespace LinuxSampler { |
43 |
|
|
44 |
std::map<String, InstrumentEditorFactory::InnerFactory*> InstrumentEditorFactory::InnerFactories; |
std::map<String, InstrumentEditorFactory::InnerFactory*> InstrumentEditorFactory::InnerFactories; |
122 |
if(!(win32FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { |
if(!(win32FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { |
123 |
String sPath = (String)CONFIG_PLUGIN_DIR + ((String)"\\" + (String)win32FindData.cFileName); |
String sPath = (String)CONFIG_PLUGIN_DIR + ((String)"\\" + (String)win32FindData.cFileName); |
124 |
// load the DLL (the plugins should register themselfes automatically) |
// load the DLL (the plugins should register themselfes automatically) |
125 |
void* pDLL = myhinstance = LoadLibrary( sPath.c_str() ); |
HINSTANCE hinstLib; |
126 |
if (pDLL) LoadedDLLs.push_back(pDLL); |
void* pDLL = hinstLib = LoadLibrary( sPath.c_str() ); |
127 |
else { |
if (!pDLL) { |
128 |
std::cerr << "Failed to load instrument editor plugin: " |
std::cerr << "Failed to load instrument editor plugin: " |
129 |
<< sPath << std::endl; |
<< sPath << std::endl; |
130 |
|
continue; |
131 |
|
} |
132 |
|
|
133 |
|
//(InnerFactory*) (*fn)(void); |
134 |
|
InnerFactoryRegisterFunction fn; |
135 |
|
fn = (InnerFactoryRegisterFunction) |
136 |
|
GetProcAddress( |
137 |
|
hinstLib, |
138 |
|
"createInstrumentEditorInnerFactory" |
139 |
|
); |
140 |
|
if (fn == NULL) { |
141 |
|
std::cerr << "ERROR: unable to find " |
142 |
|
"createInstrumentEditorInnerFactory() " |
143 |
|
"in DLL\n" << std::flush; |
144 |
|
FreeLibrary(hinstLib); |
145 |
|
continue; |
146 |
|
} |
147 |
|
|
148 |
|
// get the plugin instance and register it to the factory |
149 |
|
|
150 |
|
InnerFactory* pInnerFactory = (InnerFactory*)fn(); |
151 |
|
if (!pInnerFactory) { |
152 |
|
std::cerr << "ERROR: !pInnerFactory\n" << std::flush; |
153 |
|
FreeLibrary(hinstLib); |
154 |
|
continue; |
155 |
|
} |
156 |
|
InstrumentEditor* pEditor = pInnerFactory->Create(); |
157 |
|
if (InnerFactories.count(pEditor->Name())) { |
158 |
|
std::cerr << "ERROR: a plugin with name '" |
159 |
|
<< pEditor->Name() |
160 |
|
<< "' already loaded (skipping)\n" |
161 |
|
<< std::flush; |
162 |
|
pInnerFactory->Destroy(pEditor); |
163 |
|
FreeLibrary(hinstLib); |
164 |
|
continue; |
165 |
} |
} |
166 |
|
InnerFactories[pEditor->Name()] = pInnerFactory; |
167 |
|
pInnerFactory->Destroy(pEditor); |
168 |
|
|
169 |
|
LoadedDLLs.push_back(pDLL); |
170 |
} |
} |
171 |
int res = FindNextFile(hDir, &win32FindData); |
int res = FindNextFile(hDir, &win32FindData); |
172 |
if(res == 0 && GetLastError() != ERROR_NO_MORE_FILES) { |
if(res == 0 && GetLastError() != ERROR_NO_MORE_FILES) { |