From bc90511c1eb333e26e0bc0eaee62375d0e788db6 Mon Sep 17 00:00:00 2001 From: Erik van Pienbroek Date: Tue, 16 Apr 2013 11:42:11 +0200 Subject: [PATCH] win32: Prefer the use of constructors over DllMain This prevents having to depend on DllMain in static libraries Constructors are available in both the GCC build (GCC 2.7 and later) and the MSVC build (MSVC 2008 and later using _Pragma, earlier versions using #pragma) --- glib/glib-init.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/glib/glib-init.c b/glib/glib-init.c index 0032ee8..dd6ccbf 100644 --- a/glib/glib-init.c +++ b/glib/glib-init.c @@ -223,12 +223,14 @@ glib_init (void) #if defined (G_OS_WIN32) +HMODULE glib_dll = NULL; + +#if defined (DLL_EXPORT) + BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved); -HMODULE glib_dll; - BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, @@ -238,14 +240,6 @@ DllMain (HINSTANCE hinstDLL, { case DLL_PROCESS_ATTACH: glib_dll = hinstDLL; - g_crash_handler_win32_init (); - g_clock_win32_init (); -#ifdef THREADS_WIN32 - g_thread_win32_init (); -#endif - glib_init (); - /* must go after glib_init */ - g_console_win32_init (); break; case DLL_THREAD_DETACH: @@ -259,7 +256,10 @@ DllMain (HINSTANCE hinstDLL, return TRUE; } -#elif defined (G_HAS_CONSTRUCTORS) +#endif /* defined (DLL_EXPORT) */ +#endif /* defined (G_OS_WIN32) */ + +#if defined (G_HAS_CONSTRUCTORS) #ifdef G_DEFINE_CONSTRUCTOR_NEEDS_PRAGMA #pragma G_DEFINE_CONSTRUCTOR_PRAGMA_ARGS(glib_init_ctor) @@ -269,7 +266,15 @@ G_DEFINE_CONSTRUCTOR(glib_init_ctor) static void glib_init_ctor (void) { +#if defined (G_OS_WIN32) + g_clock_win32_init (); +#ifdef THREADS_WIN32 + g_thread_win32_init (); +#endif /* defined (THREADS_WIN32) */ +#endif /* defined (G_OS_WIN32) */ glib_init (); + /* must go after glib_init */ + g_console_win32_init (); } #else -- 1.8.2