[PATCH 3/3] winedump: Use a switch in the generated DllMain().

Michael Stefaniuc mstefani at redhat.de
Sun Jan 13 10:53:02 CST 2008


I checked the last couple (7-10) of new dll submission and with one
exception all used the switch statement to implement DllMain.  This
should make the code generated by winedump useable for a stub DLL.

Tested by generating a stub mfc42.dll and compiling the generated code.
---
 tools/winedump/output.c |   37 ++++++++++++++++---------------------
 1 files changed, 16 insertions(+), 21 deletions(-)

diff --git a/tools/winedump/output.c b/tools/winedump/output.c
index 178fb48..66c5e4d 100644
--- a/tools/winedump/output.c
+++ b/tools/winedump/output.c
@@ -238,35 +238,30 @@ void  output_c_preamble (void)
 
   fprintf (cfile,
            "BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID "
-           "lpvReserved)\n{\n\tTRACE(\"(0x%%p, %%d, %%p)\\n\",hinstDLL,"
-           "fdwReason,lpvReserved);\n\n\t"
-           "if (fdwReason == DLL_WINE_PREATTACH) return FALSE;\t"
-           "/* prefer native version */\n\n\t"
-           "if (fdwReason == DLL_PROCESS_ATTACH)\n\t{\n\t\t");
+           "lpvReserved)\n{\n"
+           "\tTRACE(\"(0x%%p, %%d, %%p)\\n\", hinstDLL, fdwReason, lpvReserved);\n"
+           "\n\tswitch (fdwReason)\n\t{\n"
+           "\t\tcase DLL_WINE_PREATTACH:\n"
+           "\t\t\treturn FALSE;    /* prefer native version */\n"
+           "\t\tcase DLL_PROCESS_ATTACH:\n");
 
   if (globals.forward_dll)
-  {
-    fprintf (cfile,
-             "hDLL = LoadLibraryA( \"%s\" );\n\t\t"
-             "TRACE(\":Forwarding DLL (%s) loaded (%%ld)\\n\",(LONG)hDLL);",
+    fprintf (cfile, "\t\t\thDLL = LoadLibraryA(\"%s\");\n"
+             "\t\t\tTRACE(\"Forwarding DLL (%s) loaded (%%p)\\n\", hDLL);\n",
              globals.forward_dll, globals.forward_dll);
-  }
   else
-    fputs ("/* FIXME: Initialisation */", cfile);
+    fprintf (cfile, "\t\t\t/* FIXME: Initialisation */\n"
+             "\t\t\tDisableThreadLibraryCalls(hinstDLL);\n\t\t\tbreak;\n");
 
-  fputs ("\n\t}\n\telse if (fdwReason == DLL_PROCESS_DETACH)\n\t{\n\t\t",
-         cfile);
+  fprintf (cfile, "\t\t\tbreak;\n\t\tcase DLL_PROCESS_DETACH:\n");
 
   if (globals.forward_dll)
-  {
-    fprintf (cfile,
-             "FreeLibrary( hDLL );\n\t\tTRACE(\":Forwarding DLL (%s)"
-             " freed\\n\");", globals.forward_dll);
-  }
-  else
-    fputs ("/* FIXME: Cleanup */", cfile);
+    fprintf (cfile, "\t\t\tFreeLibrary(hDLL);\n"
+             "\t\t\tTRACE(\"Forwarding DLL (%s) freed\\n\");\n",
+             globals.forward_dll);
 
-  fputs ("\n\t}\n\n\treturn TRUE;\n}\n\n\n", cfile);
+  fprintf (cfile, "\t\t\tbreak;\n\t\tdefault:\n\t\t\tbreak;\n\t}\n\n"
+           "\treturn TRUE;\n}\n\n\n");
 }
 
 
-- 
1.5.4.rc3
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://www.winehq.org/pipermail/wine-patches/attachments/20080113/59825946/attachment.pgp 


More information about the wine-patches mailing list