From 3507f862c70af74c245b4622f5ca5093fdfbc2aa Mon Sep 17 00:00:00 2001 From: Jamie Reece Wilson Date: Tue, 10 Oct 2023 21:42:17 +0100 Subject: [PATCH] [+] AU_DLL.h --- Include/AU_DLL.h | 70 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 Include/AU_DLL.h diff --git a/Include/AU_DLL.h b/Include/AU_DLL.h new file mode 100644 index 0000000..6ab681d --- /dev/null +++ b/Include/AU_DLL.h @@ -0,0 +1,70 @@ +/*** + Copyright (C) 2023 J Reece Wilson (a/k/a "Reece"). All rights reserved. + + File: AU_DLL.h + Date: 2023-10-10 + Author: Reece +***/ +#pragma once + +#if defined(_AU_BUILDING_SHAREDLIB) || \ + defined(AU_DLL_NO_SHARED_CHECK) + + #if defined(AURORA_PLATFORM_WIN32) + + #if !defined(DLL_PROCESS_ATTACH) + #define HMODULE void * + #define DLL_PROCESS_ATTACH 1 + #if !defined(TRUE) + #define TRUE 1 + #endif + #endif + + extern "C" __declspec(dllimport) int __stdcall DisableThreadLibraryCalls(HMODULE hLibModule); + + #define AURORA_DLL_ATTACH(func) \ + \ + int __stdcall DllMain( \ + HMODULE hinstDLL, \ + unsigned long fdwReason, \ + void *lpvReserved) \ + { \ + if (fdwReason == DLL_PROCESS_ATTACH) \ + { \ + (void)DisableThreadLibraryCalls(hinstDLL); \ + func(); \ + } \ + return TRUE; \ + } + + #elif defined(AURORA_COMPILER_CLANG) || defined(AURORA_COMPILER_GCC) + + #define AURORA_DLL_ATTACH(func) \ + __attribute__((constructor)) \ + static void FuncTlsHook ## __COUNTER__(void) \ + { \ + func(); \ + } + + #elif defined(__cplusplus) + + struct TlsHook + { + TlsHook(AuVoidFunc func) + { + a = 3; + if (func) + { + func(); + } + } + AuUInt32 a; + }; + + #define AURORA_DLL_ATTACH(func) \ + static TlsHook gTlsHook ## __COUNTER__(func); + + #endif +#else + #define AURORA_DLL_ATTACH(func) +#endif \ No newline at end of file