I am writing a DLL which defines a global static object.
In the object's constructor I am doing some initialization that may or may not succeed.
Is it possible to signal success or failure of the initialization process in DllMain() ? Which of the two is called first ?
Thank you.
MSDN's DllMain documentation says:
Since the code within DllMain may use the static objects, the static objects must be constructed before DllMain is run for DLL_PROCESS_ATTACH, and destroyed after it is run for DLL_PROCESS_DETACH.
You can verify this with a simple test exe and test dll.
EXE:
DLL:
Together those will print:
As you can see, the static object is constructed before
DllMain(...,DLL_PROCESS_ATTACH,...)
and destroyed afterDllMain(...,DLL_PROCESS_DETACH,...)