From ae8398281161bd827b1aee5dacb02de7c0b10d50 Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Sun, 14 Oct 2018 12:47:29 +0300 Subject: [PATCH] mdbx-windows: setup DllMain() as entry and don't linking with CRT. 17 of 17 for https://github.com/leo-yuriev/libmdbx/issues/43 Change-Id: Ie3b37633ab081ca4ba2dc485e67de96df032a3df --- dll.vcxproj | 8 ++++++++ src/lck-windows.c | 13 +++++++++++++ 2 files changed, 21 insertions(+) diff --git a/dll.vcxproj b/dll.vcxproj index c9e6d975..e808a124 100644 --- a/dll.vcxproj +++ b/dll.vcxproj @@ -133,6 +133,9 @@ Size true true + true + false + All MachineX86 @@ -142,6 +145,7 @@ true UseLinkTimeCodeGeneration ntdll.lib;$(IntermediateOutputPath)mdbx_ntdll_extra.lib;kernel32.lib;advapi32.lib;%(AdditionalDependencies) + true Generate fake-library mdbx_ntdll_extra.lib for $(PlatformTarget) @@ -185,10 +189,14 @@ true true EnableAllWarnings + true + false + All UseLinkTimeCodeGeneration ntdll.lib;$(IntermediateOutputPath)mdbx_ntdll_extra.lib;kernel32.lib;advapi32.lib;%(AdditionalDependencies) + true Generate fake-library mdbx_ntdll_extra.lib for $(PlatformTarget) diff --git a/src/lck-windows.c b/src/lck-windows.c index b0db378a..478c79df 100644 --- a/src/lck-windows.c +++ b/src/lck-windows.c @@ -27,6 +27,19 @@ static void mdbx_winnt_import(void); #ifdef MDBX_BUILD_DLL +/* DEBUG/CHECKED builds still require MSVC's CRT for runtime checks. + * + * Therefore we don't define dll's entry point for debug/checked builds by MSVC. + * In this case MSVC's will automatically use DllMainCRTStartup() from CRT + * library, which also automatically call DllMain() from our mdbx.dll + * + * On the other side, for RELEASE builds + * we explicitly define DllMain() as the entry point and don't linking with + * any CRT libraries (IgnoreAllDefaultLibraries = Yes). */ +#if !defined(_MSC_VER) || defined(NDEBUG) +#pragma comment(linker, "/ENTRY:DllMain") +#endif + BOOL APIENTRY DllMain(HANDLE module, DWORD reason, LPVOID reserved) #else #if !MDBX_CONFIG_MANUAL_TLS_CALLBACK