1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-15 15:49:36 +02:00

A macro for boilerplate to generate required module entry points

This commit is contained in:
Paul Licameli 2020-10-20 11:18:46 -04:00
parent fd94b66483
commit e7f8f36700
4 changed files with 27 additions and 68 deletions

View File

@ -35,11 +35,6 @@ click from the menu into the actual function to be called.
/*
There are several functions that can be used in a GUI module.
//#define versionFnName "GetVersionString"
If the version is wrong, the module will be rejected.
That is it will be loaded and then unloaded.
//#define ModuleDispatchName "ModuleDispatch"
The most useful function. See the example in this
file. It has several cases/options in it.
@ -84,18 +79,7 @@ static CommandHandlerObject &ident(AudacityProject&project)
return project;
}
// GetVersionString
// REQUIRED for the module to be accepted by Audacity.
// Without it Audacity will see a version number mismatch.
extern DLL_API const wxChar * GetVersionString();
const wxChar * GetVersionString()
{
// Make sure that this version of the module requires the version
// of Audacity it is built with.
// For now, the versions must match exactly for Audacity to
// agree to load the module.
return AUDACITY_VERSION_STRING;
}
DEFINE_VERSION_CHECK
namespace {
void RegisterMenuItems()

View File

@ -92,10 +92,6 @@
/*
There are several functions that can be used in a GUI module.
//#define versionFnName "GetVersionString"
If the version is wrong, the module will be rejected.
That is it will be loaded and then unloaded.
//#define ModuleDispatchName "ModuleDispatch"
The most useful function. See the example in this
file. It has several cases/options in it.
@ -130,21 +126,12 @@ void RegisterMenuItems()
}
}
DEFINE_VERSION_CHECK
extern "C"
{
static NyqBench *gBench = NULL;
extern DLL_API const wxChar * GetVersionString();
// GetVersionString
// REQUIRED for the module to be accepted by Audacity.
// Without it Audacity will see a version number mismatch.
const wxChar * GetVersionString()
{
// For now, the versions must match exactly for Audacity to
// agree to load the module.
return AUDACITY_VERSION_STRING;
}
extern int DLL_API ModuleDispatch(ModuleDispatchTypes type);
// ModuleDispatch
// is called by Audacity to initialize/terminate the module

View File

@ -19,10 +19,6 @@
/*
There are several functions that can be used in a GUI module.
//#define versionFnName "GetVersionString"
If the version is wrong, the module will be rejected.
That is it will be loaded and then unloaded.
//#define ModuleDispatchName "ModuleDispatch"
The most useful function. See the example in this
file. It has several cases/options in it.
@ -44,40 +40,10 @@ typedef DLL_IMPORT int (*tpExecScriptServerFunc)( wxString * pIn, wxString * pOu
static tpExecScriptServerFunc pScriptServerFn=NULL;
DEFINE_MODULE_ENTRIES
extern "C" {
DLL_API const wxChar * GetVersionString()
{
// Make sure that this version of the module requires the version
// of Audacity it is built with.
// For now the versions must match exactly for Audacity to
// agree to load the module.
return AUDACITY_VERSION_STRING;
}
extern int DLL_API ModuleDispatch(ModuleDispatchTypes type);
// ModuleDispatch
// is called by Audacity to initialize/terminate the module
// We don't (yet) do anything in this, since we have a special function for the scripter
// all we need to do is return 1.
int ModuleDispatch(ModuleDispatchTypes type){
switch (type){
case AppInitialized:{
}
break;
case AppQuiting: {
}
break;
case ProjectInitialized: {
}
break;
default:
break;
}
return 1;
}
// And here is our special registration function.
int DLL_API RegScriptServerFunc( tpExecScriptServerFunc pFn )
{

View File

@ -31,4 +31,26 @@ enum ModuleDispatchTypes
ProjectClosing
};
// Macro generates one of the required entry points of a module
// GetVersionString
// REQUIRED for the module to be accepted by Audacity.
// Without it Audacity will see a version number mismatch.
#define DEFINE_VERSION_CHECK \
extern "C" { \
DLL_API const wchar_t * GetVersionString() \
{ \
/* Make sure that this version of the module requires the version \
of Audacity it is built with. \
For now, the versions must match exactly for Audacity to \
agree to load the module. */ \
return AUDACITY_VERSION_STRING; \
} \
}
// Macro generates minimal required entry points to load a module
// Use it when you don't care about event notifications from the application
#define DEFINE_MODULE_ENTRIES \
DEFINE_VERSION_CHECK \
extern "C" DLL_API int ModuleDispatch(ModuleDispatchTypes type){ return 1; }
#endif