xref: /vim-8.2.3635/src/os_w32exe.c (revision 2bf24176)
1 /* vi:set ts=8 sts=4 sw=4:
2  *
3  * VIM - Vi IMproved		by Bram Moolenaar
4  *				GUI support by Robert Webb
5  *
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  */
10 /*
11  * Windows GUI: main program (EXE) entry point:
12  *
13  * Ron Aaron <[email protected]> wrote this and  the DLL support code.
14  */
15 #include "vim.h"
16 
17 #ifdef __MINGW32__
18 # ifndef _cdecl
19 #  define _cdecl
20 # endif
21 #endif
22 
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 **);
32 
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
40 
41 /*ARGSUSED*/
42     int WINAPI
43 WinMain(
44     HINSTANCE	hInstance,
45     HINSTANCE	hPrevInst,
46     LPSTR	lpszCmdLine,
47     int		nCmdShow)
48 {
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
57 
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);
61 
62     argc = get_cmd_args(prog, (char *)lpszCmdLine, &argv, &tofree);
63     if (argc == 0)
64     {
65 	MessageBox(0, "Could not allocate memory for command line.",
66 							      "VIM Error", 0);
67 	return 0;
68     }
69 
70 #ifdef DYNAMIC_GETTEXT
71     /* Initialize gettext library */
72     dyn_libintl_init(NULL);
73 #endif
74 
75 #ifdef VIMDLL
76     // LoadLibrary - get name of dll to load in here:
77     p = strrchr(prog, '\\');
78     if (p != NULL)
79     {
80 # ifdef DEBUG
81 	strcpy(p+1, "vim32d.dll");
82 # else
83 	strcpy(p+1, "vim32.dll");
84 # endif
85     }
86     hLib = LoadLibrary(prog);
87     if (hLib == NULL)
88     {
89 	MessageBox(0, _("Could not load vim32.dll!"), _("VIM Error"), 0);
90 	goto errout;
91     }
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)
98     {
99 	MessageBox(0, _("Could not fix up function pointers to the DLL!"),
100 							    _("VIM Error"),0);
101 	goto errout;
102     }
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
114 	;
115 #endif
116 #ifdef FEAT_GUI
117     pSaveInst(
118 #ifdef __MINGW32__
119 	    GetModuleHandle(NULL)
120 #else
121 	    hInstance
122 #endif
123 	    );
124 #endif
125     pmain(argc, argv);
126 
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
137 
138     return 0;
139 }
140 #endif
141