Cleanup
[carla.git] / source / plugin / carla-vst-export-bridged.cpp
blobf06bbcf0019fa828698e79d2efa41f2620a64fd0
1 /*
2 * Carla Native Plugins
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"
21 #ifdef __WINE__
22 #error This file is not meant to be used by wine!
23 #endif
24 #ifndef CARLA_OS_WIN
25 #error This file is only meant to be used by mingw compilers!
26 #endif
27 #ifndef CARLA_PLUGIN_SYNTH
28 #error CARLA_PLUGIN_SYNTH undefined
29 #endif
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;
43 CARLA_PLUGIN_EXPORT
44 BOOL WINAPI DllMain(HINSTANCE hInst, DWORD reason, LPVOID)
46 if (reason == DLL_PROCESS_ATTACH)
47 currentModuleHandle = hInst;
48 return 1;
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];
59 filename[0] = 0;
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);
65 if (lib == nullptr)
67 carla_stderr2("lib_open failed: %s", lib_error(filename));
68 return nullptr;
71 sCallback = lib_symbol<MainCallback>(lib, "VSTPluginMain");
74 CARLA_SAFE_ASSERT_RETURN(sCallback != nullptr, nullptr);
75 return sCallback(audioMaster);