diff options
author | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 17:22:36 +0200 |
---|---|---|
committer | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 17:22:36 +0200 |
commit | ecb1524f8da7901338b263384fed3c612f117b4c (patch) | |
tree | e7e06423fe27ea5ab45f27fc4b39ae597ba72490 /zen/FindFilePlus | |
parent | 5.10 (diff) | |
download | FreeFileSync-ecb1524f8da7901338b263384fed3c612f117b4c.tar.gz FreeFileSync-ecb1524f8da7901338b263384fed3c612f117b4c.tar.bz2 FreeFileSync-ecb1524f8da7901338b263384fed3c612f117b4c.zip |
5.11
Diffstat (limited to 'zen/FindFilePlus')
-rw-r--r-- | zen/FindFilePlus/dll_main.cpp | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/zen/FindFilePlus/dll_main.cpp b/zen/FindFilePlus/dll_main.cpp index ab3b25a3..caa5930d 100644 --- a/zen/FindFilePlus/dll_main.cpp +++ b/zen/FindFilePlus/dll_main.cpp @@ -4,12 +4,48 @@ // * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * // ************************************************************************** - #define WIN32_LEAN_AND_MEAN #include <zen/win.h> #include "init_dll_binding.h" +/* +http://www.microsoft.com/whdc/driver/kernel/DLL_bestprac.mspx +"DllMain is called while the loader-lock is held. [...] You cannot call any function in +DllMain that directly or indirectly tries to acquire the loader lock. Otherwise, you will +introduce the possibility that your application deadlocks or crashes." + +it's even worse: http://msdn.microsoft.com/en-us/library/windows/desktop/ms682583(v=vs.85).aspx +"If your DLL is linked with the C run-time library (CRT), the entry point provided by the CRT calls the constructors +and destructors for global and static C++ objects. Therefore, these restrictions for DllMain also apply to constructors +and destructors and any code that is called from them." + +Example: http://blog.barthe.ph/2009/07/30/no-stdlib-in-dllmai/ + +Empirical study on DLL initialization order +------------------------------------------- +I. statically linked DLL: + DLL, static object constructors + DLL, DllMain(): DLL_PROCESS_ATTACH + main thread, static object constructors + main thread, enter main() + DLL, DllMain(): DLL_THREAD_ATTACH + DLL, DllMain(): DLL_THREAD_DETACH + main thread, exit main() + main thread, static object destructors + DLL, DllMain(): DLL_PROCESS_DETACH + DLL, static object destructors + +II. dynamically linked DLL (living in main()): + main thread, static object constructors + main thread, main(): LoadLibrary + DLL, static object constructors + DLL, DllMain(): DLL_PROCESS_ATTACH + main thread, main(): FreeLibrary + DLL, DllMain(): DLL_PROCESS_DETACH + DLL, static object destructors + main thread, static object destructors +*/ //optional: add init/teardown logic here BOOL APIENTRY DllMain(HINSTANCE hinstDLL, |