Jacek Caban : msvcrt: Provide EXE entry points in importlib.

Alexandre Julliard julliard at winehq.org
Thu Jan 23 15:48:50 CST 2020


Module: wine
Branch: master
Commit: bb9fb27bc4c265e751b88b1d8d4c835438e7fc5c
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=bb9fb27bc4c265e751b88b1d8d4c835438e7fc5c

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Tue Jan 21 19:58:50 2020 +0100

msvcrt: Provide EXE entry points in importlib.

Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/msvcrt/Makefile.in    |  5 ++++
 dlls/msvcrt/crt_gccmain.c  | 31 ++++++++++++++++++++++++
 dlls/msvcrt/crt_main.c     | 59 +++++++++++++++++++++++++++++++++++++++++++++
 dlls/msvcrt/crt_winmain.c  | 58 ++++++++++++++++++++++++++++++++++++++++++++
 dlls/msvcrt/crt_wmain.c    | 59 +++++++++++++++++++++++++++++++++++++++++++++
 dlls/msvcrt/crt_wwinmain.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 272 insertions(+)

diff --git a/dlls/msvcrt/Makefile.in b/dlls/msvcrt/Makefile.in
index d0237fd891..0b8fdf19c7 100644
--- a/dlls/msvcrt/Makefile.in
+++ b/dlls/msvcrt/Makefile.in
@@ -6,6 +6,11 @@ DELAYIMPORTS = advapi32 user32
 C_SRCS = \
 	console.c \
 	cpp.c \
+	crt_gccmain.c \
+	crt_main.c \
+	crt_winmain.c \
+	crt_wmain.c \
+	crt_wwinmain.c \
 	ctype.c \
 	data.c \
 	dir.c \
diff --git a/dlls/msvcrt/crt_gccmain.c b/dlls/msvcrt/crt_gccmain.c
new file mode 100644
index 0000000000..ed25f385d1
--- /dev/null
+++ b/dlls/msvcrt/crt_gccmain.c
@@ -0,0 +1,31 @@
+/*
+ * __main entry point
+ *
+ * Copyright 2019 Jacek Caban for CodeWeavers
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#if 0
+#pragma makedep implib
+#endif
+
+#ifdef __MINGW32__
+
+/* mingw compilers emit call to __main() when main() function is defined.
+ * it's used by crt to call global constructors and register global destructors. */
+void __cdecl __main(void) {}
+
+#endif
diff --git a/dlls/msvcrt/crt_main.c b/dlls/msvcrt/crt_main.c
new file mode 100644
index 0000000000..7502f30075
--- /dev/null
+++ b/dlls/msvcrt/crt_main.c
@@ -0,0 +1,59 @@
+/*
+ * mainCRTStartup default entry point
+ *
+ * Copyright 2019 Jacek Caban for CodeWeavers
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#if 0
+#pragma makedep implib
+#endif
+
+#ifdef __MINGW32__
+
+#include "msvcrt.h"
+
+#include "windef.h"
+#include "winbase.h"
+
+/* FIXME: Use msvcrt headers once we move to PE file */
+void __cdecl exit(int);
+void __cdecl __getmainargs(int *, char ***, char ***, int, int *);
+void __cdecl __set_app_type(int);
+
+int __cdecl main(int argc, char **argv, char **env);
+
+static const IMAGE_NT_HEADERS *get_nt_header( void )
+{
+    extern IMAGE_DOS_HEADER __ImageBase;
+    return (const IMAGE_NT_HEADERS *)((char *)&__ImageBase + __ImageBase.e_lfanew);
+}
+
+int __cdecl mainCRTStartup(void)
+{
+    int argc, new_mode =  0, ret;
+    char **argv, **env;
+
+    __getmainargs(&argc, &argv, &env, 0, &new_mode);
+    __set_app_type(get_nt_header()->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI ? 2 : 1);
+
+    ret = main(argc, argv, env);
+
+    exit(ret);
+    return ret;
+}
+
+#endif
diff --git a/dlls/msvcrt/crt_winmain.c b/dlls/msvcrt/crt_winmain.c
new file mode 100644
index 0000000000..27e0283cbf
--- /dev/null
+++ b/dlls/msvcrt/crt_winmain.c
@@ -0,0 +1,58 @@
+/*
+ * main default entry point for exe files
+ *
+ * Copyright 2005 Alexandre Julliard
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#if 0
+#pragma makedep implib
+#endif
+
+#ifdef __MINGW32__
+
+#include <stdarg.h>
+#include "windef.h"
+#include "winbase.h"
+#include "winuser.h"
+
+int __cdecl main( int argc, char *argv[] )
+{
+    STARTUPINFOA info;
+    char *cmdline = GetCommandLineA();
+    int bcount = 0;
+    BOOL in_quotes = FALSE;
+
+    while (*cmdline)
+    {
+        if ((*cmdline == '\t' || *cmdline == ' ') && !in_quotes) break;
+        else if (*cmdline == '\\') bcount++;
+        else if (*cmdline == '\"')
+        {
+            if (!(bcount & 1)) in_quotes = !in_quotes;
+            bcount = 0;
+        }
+        else bcount = 0;
+        cmdline++;
+    }
+    while (*cmdline == '\t' || *cmdline == ' ') cmdline++;
+
+    GetStartupInfoA( &info );
+    if (!(info.dwFlags & STARTF_USESHOWWINDOW)) info.wShowWindow = SW_SHOWNORMAL;
+    return WinMain( GetModuleHandleA(0), 0, cmdline, info.wShowWindow );
+}
+
+#endif
diff --git a/dlls/msvcrt/crt_wmain.c b/dlls/msvcrt/crt_wmain.c
new file mode 100644
index 0000000000..0588d5bdce
--- /dev/null
+++ b/dlls/msvcrt/crt_wmain.c
@@ -0,0 +1,59 @@
+/*
+ * wmainCRTStartup default entry point
+ *
+ * Copyright 2019 Jacek Caban for CodeWeavers
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#if 0
+#pragma makedep implib
+#endif
+
+#ifdef __MINGW32__
+
+#include "msvcrt.h"
+
+#include "windef.h"
+#include "winbase.h"
+
+/* FIXME: Use msvcrt headers once we move to PE file */
+void __cdecl exit(int);
+void __cdecl __wgetmainargs(int *, WCHAR ***, WCHAR ***, int, int *);
+void __cdecl __set_app_type(int);
+
+int __cdecl wmain(int argc, WCHAR **argv, WCHAR **env);
+
+static const IMAGE_NT_HEADERS *get_nt_header( void )
+{
+    extern IMAGE_DOS_HEADER __ImageBase;
+    return (const IMAGE_NT_HEADERS *)((char *)&__ImageBase + __ImageBase.e_lfanew);
+}
+
+int __cdecl wmainCRTStartup(void)
+{
+    int argc, new_mode =  0, ret;
+    WCHAR **argv, **env;
+
+    __wgetmainargs(&argc, &argv, &env, 0, &new_mode);
+    __set_app_type(get_nt_header()->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI ? 2 : 1);
+
+    ret = wmain(argc, argv, env);
+
+    exit(ret);
+    return ret;
+}
+
+#endif
diff --git a/dlls/msvcrt/crt_wwinmain.c b/dlls/msvcrt/crt_wwinmain.c
new file mode 100644
index 0000000000..2c53b744b5
--- /dev/null
+++ b/dlls/msvcrt/crt_wwinmain.c
@@ -0,0 +1,60 @@
+/*
+ * main default entry point for Unicode exe files
+ *
+ * Copyright 2005 Alexandre Julliard
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#if 0
+#pragma makedep implib
+#endif
+
+#ifdef __MINGW32__
+
+#include <stdarg.h>
+#include "windef.h"
+#include "winbase.h"
+#include "winuser.h"
+
+int WINAPI wWinMain(HINSTANCE,HINSTANCE,LPWSTR,int);
+
+int __cdecl wmain( int argc, WCHAR *argv[] )
+{
+    STARTUPINFOW info;
+    WCHAR *cmdline = GetCommandLineW();
+    int bcount = 0;
+    BOOL in_quotes = FALSE;
+
+    while (*cmdline)
+    {
+        if ((*cmdline == '\t' || *cmdline == ' ') && !in_quotes) break;
+        else if (*cmdline == '\\') bcount++;
+        else if (*cmdline == '\"')
+        {
+            if (!(bcount & 1)) in_quotes = !in_quotes;
+            bcount = 0;
+        }
+        else bcount = 0;
+        cmdline++;
+    }
+    while (*cmdline == '\t' || *cmdline == ' ') cmdline++;
+
+    GetStartupInfoW( &info );
+    if (!(info.dwFlags & STARTF_USESHOWWINDOW)) info.wShowWindow = SW_SHOWNORMAL;
+    return wWinMain( GetModuleHandleW(0), 0, cmdline, info.wShowWindow );
+}
+
+#endif




More information about the wine-cvs mailing list