diff --git a/source/utility.hpp b/source/utility.hpp index 0181bb6..c79e593 100644 --- a/source/utility.hpp +++ b/source/utility.hpp @@ -15,8 +15,6 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA -#ifndef OBS_FFMPEG_UTILITY_HPP -#define OBS_FFMPEG_UTILITY_HPP #pragma once #include "version.hpp" @@ -45,4 +43,31 @@ #define vstr(s) dstr(s) #define dstr(s) #s -#endif OBS_FFMPEG_UTILITY_HPP +// Initializer +#ifdef __cplusplus +#define INITIALIZER(f) \ + static void f(void); \ + struct f##_t_ { \ + f##_t_(void) \ + { \ + f(); \ + } \ + }; \ + static f##_t_ f##_; \ + static void f(void) +#elif defined(_MSC_VER) +#pragma section(".CRT$XCU", read) +#define INITIALIZER2_(f, p) \ + static void f(void); \ + __declspec(allocate(".CRT$XCU")) void (*f##_)(void) = f; \ + __pragma(comment(linker, "/include:" p #f "_")) static void f(void) +#ifdef _WIN64 +#define INITIALIZER(f) INITIALIZER2_(f, "") +#else +#define INITIALIZER(f) INITIALIZER2_(f, "_") +#endif +#else +#define INITIALIZER(f) \ + static void f(void) __attribute__((constructor)); \ + static void f(void) +#endif