[CRT/MINGW-W64]
authorAmine Khaldi <amine.khaldi@reactos.org>
Sat, 30 Apr 2011 14:26:21 +0000 (14:26 +0000)
committerAmine Khaldi <amine.khaldi@reactos.org>
Sat, 30 Apr 2011 14:26:21 +0000 (14:26 +0000)
* Reorganize dll entry and C runtime initialization. By Kai Tietz.

svn path=/trunk/; revision=51504

reactos/lib/3rdparty/mingw/crtdll.c

index 55665bd..001cbd7 100644 (file)
@@ -180,33 +180,33 @@ __DllMainCRTStartup (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved)
        goto i__leave;
     }
   _pei386_runtime_relocator ();
-  if (retcode && dwReason == DLL_PROCESS_ATTACH)
-    __main ();
   if (dwReason == DLL_PROCESS_ATTACH || dwReason == DLL_THREAD_ATTACH)
     {
+        retcode = _CRT_INIT (hDllHandle, dwReason, lpreserved);
+        if (!retcode)
+          goto i__leave;
         retcode = DllEntryPoint (hDllHandle, dwReason, lpreserved);
-       if (retcode)
-         retcode = _CRT_INIT (hDllHandle, dwReason, lpreserved);
        if (! retcode)
-         goto i__leave;
+         {
+           if (dwReason == DLL_PROCESS_ATTACH)
+             _CRT_INIT (hDllHandle, DLL_PROCESS_DETACH, lpreserved);
+           goto i__leave;
+         }
     }
+  if (dwReason == DLL_PROCESS_ATTACH)
+    __main ();
   retcode = DllMain(hDllHandle,dwReason,lpreserved);
-  if ((dwReason == DLL_PROCESS_ATTACH) && ! retcode)
+  if (dwReason == DLL_PROCESS_ATTACH && ! retcode)
     {
        DllMain (hDllHandle, DLL_PROCESS_DETACH, lpreserved);
-       _CRT_INIT (hDllHandle, DLL_PROCESS_DETACH, lpreserved);
        DllEntryPoint (hDllHandle, DLL_PROCESS_DETACH, lpreserved);
+       _CRT_INIT (hDllHandle, DLL_PROCESS_DETACH, lpreserved);
     }
   if (dwReason == DLL_PROCESS_DETACH || dwReason == DLL_THREAD_DETACH)
     {
+        retcode = DllEntryPoint (hDllHandle, dwReason, lpreserved);
        if (_CRT_INIT (hDllHandle, dwReason, lpreserved) == FALSE)
-         {
-           retcode = FALSE;
-         }
-       if (retcode)
-         {
-           retcode = DllEntryPoint (hDllHandle, dwReason, lpreserved);
-         }
+         retcode = FALSE;
     }
 i__leave:
   __native_dllmain_reason = UINT_MAX;