[+] AU_DLL.h
This commit is contained in:
parent
c30cada865
commit
3507f862c7
70
Include/AU_DLL.h
Normal file
70
Include/AU_DLL.h
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user