y2k
y2k

Reputation: 65996

Which functions are called before DllMain()?

Which functions are called prior to DllMain()? If more than one during the C runtime initialization, then the order is important.

Upvotes: 4

Views: 1571

Answers (3)

Martin Rosenau
Martin Rosenau

Reputation: 18493

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().

Upvotes: 3

Rahul Tripathi
Rahul Tripathi

Reputation: 172398

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.

Upvotes: 5

Medinoc
Medinoc

Reputation: 6608

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).

Upvotes: 3

Related Questions