Merge branch 'vim-with-runtime' into feat/code-check
[vim_extended.git] / src / os_w32exe.c
blob93a13899c21262984de1a86338f1c1da9f9dbbc1
1 /* vi:set ts=8 sts=4 sw=4:
3 * VIM - Vi IMproved by Bram Moolenaar
4 * GUI support by Robert Webb
6 * Do ":help uganda" in Vim to read copying and usage conditions.
7 * Do ":help credits" in Vim to see a list of people who contributed.
8 * See README.txt for an overview of the Vim source code.
9 */
11 * Windows GUI: main program (EXE) entry point:
13 * Ron Aaron <ronaharon@yahoo.com> wrote this and the DLL support code.
15 #include "vim.h"
17 #ifdef __MINGW32__
18 # ifndef _cdecl
19 # define _cdecl
20 # endif
21 #endif
23 /* cproto doesn't create a prototype for main() */
24 int _cdecl
25 #if defined(FEAT_GUI_W32)
26 VimMain
27 #else
28 main
29 #endif
30 __ARGS((int argc, char **argv));
31 static int (_cdecl *pmain)(int, char **);
33 #ifndef PROTO
34 #ifdef FEAT_GUI
35 #ifndef VIMDLL
36 void _cdecl SaveInst(HINSTANCE hInst);
37 #endif
38 static void (_cdecl *pSaveInst)(HINSTANCE);
39 #endif
41 /*ARGSUSED*/
42 int WINAPI
43 WinMain(
44 HINSTANCE hInstance,
45 HINSTANCE hPrevInst,
46 LPSTR lpszCmdLine,
47 int nCmdShow)
49 int argc = 0;
50 char **argv;
51 char *tofree;
52 char prog[256];
53 #ifdef VIMDLL
54 char *p;
55 HANDLE hLib;
56 #endif
58 /* Ron: added full path name so that the $VIM variable will get set to our
59 * startup path (so the .vimrc file can be found w/o a VIM env. var.) */
60 GetModuleFileName(NULL, prog, 255);
62 argc = get_cmd_args(prog, (char *)lpszCmdLine, &argv, &tofree);
63 if (argc == 0)
65 MessageBox(0, "Could not allocate memory for command line.",
66 "VIM Error", 0);
67 return 0;
70 #ifdef DYNAMIC_GETTEXT
71 /* Initialize gettext library */
72 dyn_libintl_init(NULL);
73 #endif
75 #ifdef VIMDLL
76 // LoadLibrary - get name of dll to load in here:
77 p = strrchr(prog, '\\');
78 if (p != NULL)
80 # ifdef DEBUG
81 strcpy(p+1, "vim32d.dll");
82 # else
83 strcpy(p+1, "vim32.dll");
84 # endif
86 hLib = LoadLibrary(prog);
87 if (hLib == NULL)
89 MessageBox(0, _("Could not load vim32.dll!"), _("VIM Error"), 0);
90 goto errout;
92 // fix up the function pointers
93 # ifdef FEAT_GUI
94 pSaveInst = GetProcAddress(hLib, (LPCSTR)2);
95 # endif
96 pmain = GetProcAddress(hLib, (LPCSTR)1);
97 if (pmain == NULL)
99 MessageBox(0, _("Could not fix up function pointers to the DLL!"),
100 _("VIM Error"),0);
101 goto errout;
103 #else
104 # ifdef FEAT_GUI
105 pSaveInst = SaveInst;
106 # endif
107 pmain =
108 # if defined(FEAT_GUI_W32)
109 //&& defined(__MINGW32__)
110 VimMain
111 # else
112 main
113 # endif
115 #endif
116 #ifdef FEAT_GUI
117 pSaveInst(
118 #ifdef __MINGW32__
119 GetModuleHandle(NULL)
120 #else
121 hInstance
122 #endif
124 #endif
125 pmain(argc, argv);
127 #ifdef VIMDLL
128 FreeLibrary(hLib);
129 errout:
130 #endif
131 free(argv);
132 if (tofree != NULL)
133 free(tofree);
134 #ifdef FEAT_MBYTE
135 free_cmd_argsW();
136 #endif
138 return 0;
140 #endif