Hi,
I’ve noticed that when building an audio plug-in for Windows, if one wants to include all the available formats (AAX, RTAS and VST), it is likely that the DllMain function in the AAX wrapper will cause a multiple definition because there is no guard against it.
I think the current implementation that avoids this conflict between RTAS and VST could be extended and generalised, in order to accomodate AAX (and other possible plug-in formats in future):
First consideration: disambiguation of DllMain functions is only needed if two or more plug-in formats are to be built, thus this code could do the trick:
#if (JucePlugin_Build_AAX + JucePlugin_Build_RTAS + JucePlugin_Build_VST) > 1
# define JucePlugin_MultiDLLMain 1
#endif
Then, where each wrapper implements its DllMain function, a check against the JucePlugin_MultiDLLMain definition will tell if it can be actually named DllMain or if it needs to have a suffix (DllMainVST, DllMainRTAS, DllMainAAX and so on) to avoid conflicts with the others.
In the latter case, a proper DllMain must be implemented (in a location where it gets compiled regardless of the enabled/disabled plug-in formats), that detects in turn which of the suffixed DllMains should be called.
I think something like this will do:
#if JucePlugin_MultiDLLMain
#if JucePlugin_Build_RTAS
extern "C" BOOL WINAPI DllMainRTAS (HINSTANCE, DWORD, LPVOID);
#endif
#if JucePlugin_Build_VST
extern "C" BOOL WINAPI DllMainVST (HINSTANCE, DWORD, LPVOID);
#endif
#if JucePlugin_Build_AAX
extern "C" BOOL WINAPI DllMainAAX (HINSTANCE, DWORD, LPVOID);
#endif
extern "C" BOOL WINAPI DllMain (HINSTANCE hInstance, DWORD ul_reason_for_call, LPVOID lpReserved)
{
char moduleFileName [1024] = {0};
char* pluginExtension = moduleFileName;
GetModuleFileName (hInstance, moduleFileName, 1024);
for (char* c = moduleFileName; *c != 0; ++c)
{
if (*c == '.')
{
pluginExtension = c;
}
}
#if JucePlugin_Build_AAX
if (_stricmp (pluginExtension, ".aaxplugin") == 0)
{
return DllMainAAX (hInstance, ul_reason_for_call, lpReserved);
}
else
#endif
#if JucePlugin_Build_RTAS
if (GetModuleHandleA ("DAE.DLL") != 0)
{
return DllMainRTAS (hInstance, ul_reason_for_call, lpReserved);
}
else
#endif
{
#if JucePlugin_Build_VST
return DllMainVST (hInstance, ul_reason_for_call, lpReserved);
#else
jassertfalse;
#endif
}
}
#endif // JucePlugin_MultiDLLMain
Obviously, if this code is implemented, it replaces the previous implementation of a disambiguating DllMain present in the RTAS wrapper file juce_RTAS_DigiCode3.cpp