1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-05 22:28:57 +02:00

Fixed: Order of module function invocation; removed superfluous init function; version number now a wchar_t* to avoid linker warning.

This commit is contained in:
james.k.crook@gmail.com 2011-04-25 16:36:25 +00:00
parent 7858ff6598
commit 0e26793243

View File

@ -39,7 +39,8 @@ i.e. an alternative to the usual interface, for Audacity.
typedef wxWindow * pwxWindow; typedef wxWindow * pwxWindow;
typedef int (*tModuleInit)(int); typedef int (*tModuleInit)(int);
typedef wxString (*tVersionFn)(); //typedef wxString (*tVersionFn)();
typedef wchar_t * (*tVersionFn)();
typedef pwxWindow (*tPanelFn)(int); typedef pwxWindow (*tPanelFn)(int);
// This variable will hold the address of a subroutine in // This variable will hold the address of a subroutine in
@ -89,36 +90,14 @@ void LoadModule(wxString fname)
wxDynamicLibrary* pDLL = new wxDynamicLibrary(); wxDynamicLibrary* pDLL = new wxDynamicLibrary();
if (pDLL && pDLL->Load(fname, wxDL_LAZY)) if (pDLL && pDLL->Load(fname, wxDL_LAZY))
{ {
int result = 1; // We've loaded and initialised OK.
// A little strange. The main function is called whether or not the version is OK. // So look for special case functions:
mainFn = (tModuleInit)(pDLL->GetSymbol(wxT(initFnName))); // (a) for scripting.
if (mainFn) if( scriptFn == NULL )
result = mainFn( 0 ); scriptFn = (tpRegScriptServerFunc)(pDLL->GetSymbol(wxT(scriptFnName)));
// (b) for hijacking the entire Audacity panel.
// If the module provides a version string, check that it matches the if( pPanelHijack==NULL )
// Audacity version string. (For now, they must match exactly) pPanelHijack = (tPanelFn)(pDLL->GetSymbol(wxT(mainPanelFnName)));
tVersionFn versionFn = (tVersionFn)(pDLL->GetSymbol(wxT(versionFnName)));
bool bOK = versionFn != NULL;
if (!bOK){
wxLogWarning(wxT("The module %s does not provide a version string. It will not be loaded."), fname.c_str());
}
else {
wxString moduleVersion = versionFn();
bOK = moduleVersion.IsSameAs(AUDACITY_VERSION_STRING);
if( !bOK ){
wxLogError(wxT("The module %s is designed to work with Audacity version %s; it will not be loaded."), fname.c_str(), moduleVersion.c_str());
}
}
if( !bOK ){
delete pDLL;
}
else {
if(( scriptFn == NULL ) &&(result>=0 ))
scriptFn = (tpRegScriptServerFunc)(pDLL->GetSymbol(wxT(scriptFnName)));
if((pPanelHijack==NULL ) && (result>=0))
pPanelHijack = (tPanelFn)(pDLL->GetSymbol(wxT(mainPanelFnName)));
}
} }
::wxSetWorkingDirectory(saveOldCWD); ::wxSetWorkingDirectory(saveOldCWD);
@ -195,9 +174,22 @@ bool Module::Load()
return false; return false;
} }
mDispatch = (fnModuleDispatch) mLib->GetSymbol(wxT(ModuleDispatchName)); // Check version string matches. (For now, they must match exactly)
tVersionFn versionFn = (tVersionFn)(mLib->GetSymbol(wxT(versionFnName)));
if (versionFn == NULL){
wxLogWarning(wxT("The module %s does not provide a version string. It will not be loaded."), mName.c_str());
return false;
}
wxString moduleVersion = versionFn();
if( !moduleVersion.IsSameAs(AUDACITY_VERSION_STRING)) {
wxLogError(wxT("The module %s is designed to work with Audacity version %s; it will not be loaded."), mName.c_str(), moduleVersion.c_str());
return false;
}
mDispatch = (fnModuleDispatch) mLib->GetSymbol(wxT(ModuleDispatchName));
if (!mDispatch) { if (!mDispatch) {
// Module does not provide a dispacth function...
return false; return false;
} }
@ -207,7 +199,6 @@ bool Module::Load()
} }
mDispatch = NULL; mDispatch = NULL;
return false; return false;
} }