3 * Copyright (C) 2013-2022 Filipe Coelho <falktx@falktx.com>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of
8 * the License, or any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * For a full copy of the GNU General Public License see the doc/GPL.txt file.
18 #include "CarlaLibUtils.hpp"
19 #include "vestige/vestige.h"
22 #error This file is not meant to be used by wine!
25 #error This file is only meant to be used by mingw compilers!
27 #ifndef CARLA_PLUGIN_SYNTH
28 #error CARLA_PLUGIN_SYNTH undefined
31 typedef const AEffect
* (__cdecl
*MainCallback
)(audioMasterCallback
);
33 static HINSTANCE currentModuleHandle
= nullptr;
35 static HINSTANCE
getCurrentModuleInstanceHandle() noexcept
37 if (currentModuleHandle
== nullptr)
38 currentModuleHandle
= GetModuleHandleA(nullptr);
40 return currentModuleHandle
;
44 BOOL WINAPI
DllMain(HINSTANCE hInst
, DWORD reason
, LPVOID
)
46 if (reason
== DLL_PROCESS_ATTACH
)
47 currentModuleHandle
= hInst
;
51 CARLA_PLUGIN_EXPORT __cdecl
52 const AEffect
* VSTPluginMain(audioMasterCallback audioMaster
)
54 static MainCallback sCallback
= nullptr;
56 if (sCallback
== nullptr)
58 CHAR filename
[MAX_PATH
+ 256];
60 GetModuleFileName(getCurrentModuleInstanceHandle(), filename
, MAX_PATH
+ 256);
61 strcat(filename
, ".so");
63 carla_stdout("FILENAME: '%s'", filename
);
64 static const lib_t lib
= lib_open(filename
);
67 carla_stderr2("lib_open failed: %s", lib_error(filename
));
71 sCallback
= lib_symbol
<MainCallback
>(lib
, "VSTPluginMain");
74 CARLA_SAFE_ASSERT_RETURN(sCallback
!= nullptr, nullptr);
75 return sCallback(audioMaster
);