patch 9.1.0621: MS-Windows: startup code can be improved

Problem:  MS-Windows: startup code can be improved
Solution: Re-work and optimize win32 startup code
          (Ken Takata)

* Revise the code and reduce #ifdefs.
* For VIMDLL, stop using the default CRT startup code to reduce the file
  size.
  The file size becomes ~130 KB -> ~34 KB on MSVC.
* Update comments. Make them consistent between os_w32dll.c and
  os_w32exe.c.

closes: #15352

Signed-off-by: Ken Takata <kentkt@csc.jp>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Ken Takata
2024-07-26 18:46:54 +02:00
committed by Christian Brabandt
parent be82825687
commit b32d0a479d
5 changed files with 58 additions and 27 deletions

View File

@ -8,10 +8,10 @@
* See README.txt for an overview of the Vim source code.
*/
/*
* Windows GUI: main program (EXE) entry point:
* Windows GUI/Console: main program (EXE) entry point:
*
* Ron Aaron <ronaharon@yahoo.com> wrote this and the (now deleted) DLL support
* code.
* Ron Aaron <ronaharon@yahoo.com> wrote this and the DLL support code.
* Adapted by Ken Takata.
*/
#include "vim.h"
@ -20,32 +20,53 @@
__declspec(dllimport)
#endif
int VimMain(int argc, char **argv);
#ifndef VIMDLL
#ifdef VIMDLL
# define SaveInst(hInst) // Do nothing
#else
void SaveInst(HINSTANCE hInst);
#endif
#ifndef PROTO
# ifdef FEAT_GUI
#ifdef FEAT_GUI
int WINAPI
wWinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInst UNUSED,
LPWSTR lpszCmdLine UNUSED,
int nCmdShow UNUSED)
# else
{
SaveInst(hInstance);
return VimMain(0, NULL);
}
#else
int
wmain(int argc UNUSED, wchar_t **argv UNUSED)
# endif
{
# ifndef VIMDLL
# ifdef FEAT_GUI
SaveInst(hInstance);
# else
SaveInst(GetModuleHandleW(NULL));
# endif
# endif
VimMain(0, NULL);
return 0;
return VimMain(0, NULL);
}
#endif
#ifdef USE_OWNSTARTUP
// Use our own entry point and don't use the default CRT startup code to
// reduce the size of (g)vim.exe. This works only when VIMDLL is defined.
//
// For MSVC, the /GS- compiler option is needed to avoid the undefined symbol
// error. (It disables the security check. However, it affects only this
// function and doesn't have any effect on Vim itself.)
// For MinGW, the -nostdlib compiler option and the --entry linker option are
// needed.
# ifdef FEAT_GUI
void WINAPI
wWinMainCRTStartup(void)
{
VimMain(0, NULL);
}
# else
void
wmainCRTStartup(void)
{
VimMain(0, NULL);
}
# endif
#endif // USE_OWNSTARTUP