diff --git a/MG/Includes.h b/MG/Includes.h index 6763919c..508c1d97 100644 --- a/MG/Includes.h +++ b/MG/Includes.h @@ -113,6 +113,10 @@ #include "MG_Include/UncertainBool.hpp" +#ifdef _WIN32 +#include +#endif + #ifndef _WIN32 #include #include diff --git a/MG/Init.cpp b/MG/Init.cpp index 27bc3a36..997be055 100644 --- a/MG/Init.cpp +++ b/MG/Init.cpp @@ -4,14 +4,43 @@ #include "Includes.h" -__attribute__((constructor)) void MG_Initialize() { +void MG_Initialize() { MG_Util::Debug::LogInit(); MG_Util::Debug::LogI("MobileGL Initializing..."); MG_State::Init(); MG_GL::BackendLoader::Init(); } -__attribute__((destructor)) void MG_Destroy() { +void MG_Destroy() { MG_Util::Debug::LogI("MobileGL Exiting..."); MG_State::Destroy(); -} \ No newline at end of file +} + +#if defined(__linux__) || defined(__APPLE__) +__attribute__((constructor)) static void AutoInit() { + MG_Initialize(); +} + +__attribute__((destructor)) static void AutoDestroy() { + MG_Destroy(); +} +#endif + +#ifdef _WIN32 +BOOL WINAPI DllMain(HMODULE hModule, + DWORD ul_reason_for_call, + LPVOID lpReserved) +{ + switch (ul_reason_for_call) + { + case DLL_PROCESS_ATTACH: + MG_Initialize(); + break; + + case DLL_PROCESS_DETACH: + MG_Destroy(); + break; + } + return TRUE; +} +#endif \ No newline at end of file