From: Luca Bacci Date: Thu, 29 Dec 2022 13:51:43 +0000 (+0100) Subject: Simpler way to get the module HANDLE X-Git-Tag: archive/raspbian/1%0.1.106-3+rpi1^2~15^2^2~44 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=7ab8e5ee71ec3c59d1c4e568b965ac3d9d756695;p=babl.git Simpler way to get the module HANDLE Also works in case of static compilation --- diff --git a/babl/babl-util.c b/babl/babl-util.c index cab9ab1..d446a43 100644 --- a/babl/babl-util.c +++ b/babl/babl-util.c @@ -148,3 +148,14 @@ _babl_file_get_contents (const char *path, return 0; } +#ifdef _WIN32 + +extern IMAGE_DOS_HEADER __ImageBase; + +void * +get_libbabl_module (void) +{ + return &__ImageBase; +} + +#endif /* _WIN32 */ diff --git a/babl/babl-util.h b/babl/babl-util.h index 9caec36..f24101d 100644 --- a/babl/babl-util.h +++ b/babl/babl-util.h @@ -26,4 +26,12 @@ double babl_rel_avg_error (const double *imgA, const double *imgB, long samples); + +#ifdef _WIN32 + +void * +get_libbabl_module (void); + +#endif /* _WIN32 */ + #endif diff --git a/babl/babl.c b/babl/babl.c index 95ac256..57bb916 100644 --- a/babl/babl.c +++ b/babl/babl.c @@ -22,35 +22,9 @@ static int ref_count = 0; -#ifdef _WIN32 -static HMODULE libbabl_dll = NULL; - -/* Minimal DllMain that just stores the handle to this DLL */ - -/* Avoid silly "no previous prototype" gcc warning */ -BOOL WINAPI -DllMain (HINSTANCE hinstDLL, - DWORD fdwReason, - LPVOID lpvReserved); - -BOOL WINAPI -DllMain (HINSTANCE hinstDLL, - DWORD fdwReason, - LPVOID lpvReserved) -{ - switch (fdwReason) - { - case DLL_PROCESS_ATTACH: - libbabl_dll = hinstDLL; - break; - } - - return TRUE; -} - -#else +#ifndef _WIN32 #define BABL_PATH LIBDIR BABL_DIR_SEPARATOR BABL_LIBRARY -#endif /* _WIN32 */ +#endif /* * Returns a list of directories if the environment variable $BABL_PATH @@ -77,7 +51,7 @@ babl_dir_list (void) wchar_t w_filename[MAX_PATH]; DWORD nSize = sizeof (w_filename) / sizeof ((w_filename)[0]); - if (GetModuleFileNameW (libbabl_dll, w_filename, nSize) == 0) + if (GetModuleFileNameW (get_libbabl_module (), w_filename, nSize) == 0) babl_fatal ("GetModuleFilenameW failed"); filename_size = WideCharToMultiByte (CP_UTF8, 0, w_filename, -1, NULL, 0,