diff --git a/dll.vcxproj b/dll.vcxproj index 746de67b..b6cfe110 100644 --- a/dll.vcxproj +++ b/dll.vcxproj @@ -95,7 +95,7 @@ - WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBMDBX_EXPORTS;%(PreprocessorDefinitions);MDBX_DEBUG=1 + WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBMDBX_EXPORTS;MDBX_BUILD_DLL;%(PreprocessorDefinitions);MDBX_DEBUG=1 MultiThreadedDebugDLL EnableAllWarnings ProgramDatabase @@ -111,7 +111,7 @@ - WIN32;NDEBUG;_WINDOWS;_USRDLL;LIBMDBX_EXPORTS;%(PreprocessorDefinitions) + WIN32;NDEBUG;_WINDOWS;_USRDLL;LIBMDBX_EXPORTS;MDBX_BUILD_DLL;%(PreprocessorDefinitions) MultiThreadedDLL EnableAllWarnings ProgramDatabase @@ -140,7 +140,7 @@ EnableAllWarnings - WIN64;_DEBUG;_WINDOWS;_USRDLL;LIBMDBX_EXPORTS;%(PreprocessorDefinitions);MDBX_DEBUG=1 + WIN64;_DEBUG;_WINDOWS;_USRDLL;LIBMDBX_EXPORTS;MDBX_BUILD_DLL;%(PreprocessorDefinitions);MDBX_DEBUG=1 MultiThreadedDebugDLL true true @@ -148,7 +148,7 @@ - WIN64;NDEBUG;_WINDOWS;_USRDLL;LIBMDBX_EXPORTS;%(PreprocessorDefinitions) + WIN64;NDEBUG;_WINDOWS;_USRDLL;LIBMDBX_EXPORTS;MDBX_BUILD_DLL;%(PreprocessorDefinitions) MultiThreadedDLL true Full diff --git a/mdbx.h b/mdbx.h index ec283111..ddf1a040 100644 --- a/mdbx.h +++ b/mdbx.h @@ -207,6 +207,7 @@ extern LIBMDBX_API const mdbx_version_info mdbx_version; extern LIBMDBX_API const mdbx_build_info mdbx_build; #if defined(_WIN32) || defined(_WIN64) +#ifndef MDBX_BUILD_DLL /* Dll initialization callback for ability to dynamically load MDBX DLL by * LoadLibrary() on Windows versions before Windows Vista. This function MUST be @@ -222,6 +223,7 @@ extern LIBMDBX_API const mdbx_build_info mdbx_build; void LIBMDBX_API NTAPI mdbx_dll_callback(PVOID module, DWORD reason, PVOID reserved); #endif /* MDBX_CONFIG_MANUAL_TLS_CALLBACK */ +#endif /* MDBX_BUILD_DLL */ #endif /* Windows */ /* The name of the lock file in the DB environment */ diff --git a/src/lck-windows.c b/src/lck-windows.c index 7da07559..dcadcb6e 100644 --- a/src/lck-windows.c +++ b/src/lck-windows.c @@ -26,11 +26,16 @@ static void mdbx_winnt_import(void); +#ifdef MDBX_BUILD_DLL +BOOL APIENTRY DllMain(HANDLE module, DWORD reason, LPVOID reserved) +#else #if !MDBX_CONFIG_MANUAL_TLS_CALLBACK static #endif /* !MDBX_CONFIG_MANUAL_TLS_CALLBACK */ void NTAPI - mdbx_dll_callback(PVOID module, DWORD reason, PVOID reserved) { + mdbx_dll_callback(PVOID module, DWORD reason, PVOID reserved) +#endif /* MDBX_BUILD_DLL */ +{ (void)reserved; switch (reason) { case DLL_PROCESS_ATTACH: @@ -47,9 +52,12 @@ static mdbx_rthc_thread_dtor(module); break; } +#ifdef MDBX_BUILD_DLL + return TRUE; +#endif } -#if !MDBX_CONFIG_MANUAL_TLS_CALLBACK +#if !defined(MDBX_BUILD_DLL) && !MDBX_CONFIG_MANUAL_TLS_CALLBACK /* *INDENT-OFF* */ /* clang-format off */ #if defined(_MSC_VER) @@ -87,7 +95,7 @@ static #endif /* *INDENT-ON* */ /* clang-format on */ -#endif /* !MDBX_CONFIG_MANUAL_TLS_CALLBACK */ +#endif /* !defined(MDBX_BUILD_DLL) && !MDBX_CONFIG_MANUAL_TLS_CALLBACK */ /*----------------------------------------------------------------------------*/