Which functions are called prior to DllMain()? If more than one during the C runtime initialization, then the order is important.
-
At least one `main()` is called. – alk Aug 21 '13 at 20:10
-
Your question is entirely dependent on the runtime-library you're using. MS exposes several startup functions that eventually *invoke* DllMain() if you have one (they provide a default if you don't). Other C/C++ runtimes will provide possibly other startup routines that invoke yours. You can, of course, not use the C/C++ - runtime when writing Windows code, relying entirely on the WIN32 API, in which case Windows wll invoke *your* entry point directly. Good luck with that. – WhozCraig Aug 21 '13 at 20:12
3 Answers
From the source:-
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.

- 168,305
- 31
- 280
- 331
-
This means constructors of global/static objects in a DLL can't call any function in (or that depends on) any other DLL than Kernel32 and MSVCRxx. – Medinoc Aug 22 '13 at 08:13
I think only _DllMainCRTStartup() is called, which in turns calls all constructors of global C++ objects (none in the case of C) and (I'm not sure of that last one) calls DllMain().
Of course, it also calls some Kernel32 functions to initialize the CRT (for starters, it needs to allocate some memory and a TLS slot).

- 6,577
- 20
- 42
This is very compiler dependent.
DllMain() has exactly the same calling convention as the DLL's entry point so for some compilers DllMain() is the entry point of the DLL!
Other compilers use their own entry point where some DLL initializations are done before entering DllMain().
In contrast to this the entry point of an EXE file does not have any arguments and the function must never return. Therefore the WinMain() or main() function cannot be the entry point of an EXE file but there must be some preparation code that is called before WinMain() or main().

- 17,897
- 3
- 19
- 38