blob: f96bff4c8e22880b7c5a4929cfe9f1ca0833cf5b [file] [log] [blame]
Bram Moolenaaredf3f972016-08-29 22:49:24 +02001/* vi:set ts=8 sts=4 sw=4 noet:
Bram Moolenaar071d4272004-06-13 20:20:40 +00002 *
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 <ronaharon@yahoo.com> 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() */
24int _cdecl
25#if defined(FEAT_GUI_W32)
26VimMain
27#else
28 main
29#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010030 (int argc, char **argv);
Bram Moolenaar7fae6362005-06-30 22:06:41 +000031static int (_cdecl *pmain)(int, char **);
Bram Moolenaar071d4272004-06-13 20:20:40 +000032
33#ifndef PROTO
34#ifdef FEAT_GUI
35#ifndef VIMDLL
36void _cdecl SaveInst(HINSTANCE hInst);
37#endif
Bram Moolenaar7fae6362005-06-30 22:06:41 +000038static void (_cdecl *pSaveInst)(HINSTANCE);
Bram Moolenaar071d4272004-06-13 20:20:40 +000039#endif
40
41 int WINAPI
42WinMain(
Bram Moolenaar1266d672017-02-01 13:43:36 +010043 HINSTANCE hInstance UNUSED,
44 HINSTANCE hPrevInst UNUSED,
Bram Moolenaar071d4272004-06-13 20:20:40 +000045 LPSTR lpszCmdLine,
Bram Moolenaar1266d672017-02-01 13:43:36 +010046 int nCmdShow UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000047{
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +000048 int argc = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000049 char **argv;
50 char *tofree;
51 char prog[256];
52#ifdef VIMDLL
53 char *p;
54 HANDLE hLib;
55#endif
56
57 /* Ron: added full path name so that the $VIM variable will get set to our
58 * startup path (so the .vimrc file can be found w/o a VIM env. var.) */
59 GetModuleFileName(NULL, prog, 255);
60
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +000061 argc = get_cmd_args(prog, (char *)lpszCmdLine, &argv, &tofree);
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +000062 if (argc == 0)
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +000063 {
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +000064 MessageBox(0, "Could not allocate memory for command line.",
65 "VIM Error", 0);
66 return 0;
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +000067 }
68
Bram Moolenaar071d4272004-06-13 20:20:40 +000069#ifdef DYNAMIC_GETTEXT
70 /* Initialize gettext library */
Bram Moolenaar286eacd2016-01-16 18:05:50 +010071 dyn_libintl_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +000072#endif
73
74#ifdef VIMDLL
75 // LoadLibrary - get name of dll to load in here:
76 p = strrchr(prog, '\\');
77 if (p != NULL)
78 {
79# ifdef DEBUG
80 strcpy(p+1, "vim32d.dll");
81# else
82 strcpy(p+1, "vim32.dll");
83# endif
84 }
85 hLib = LoadLibrary(prog);
86 if (hLib == NULL)
87 {
88 MessageBox(0, _("Could not load vim32.dll!"), _("VIM Error"), 0);
89 goto errout;
90 }
91 // fix up the function pointers
92# ifdef FEAT_GUI
93 pSaveInst = GetProcAddress(hLib, (LPCSTR)2);
94# endif
95 pmain = GetProcAddress(hLib, (LPCSTR)1);
96 if (pmain == NULL)
97 {
98 MessageBox(0, _("Could not fix up function pointers to the DLL!"),
99 _("VIM Error"),0);
100 goto errout;
101 }
102#else
103# ifdef FEAT_GUI
104 pSaveInst = SaveInst;
105# endif
106 pmain =
107# if defined(FEAT_GUI_W32)
108 //&& defined(__MINGW32__)
109 VimMain
110# else
111 main
112# endif
113 ;
114#endif
115#ifdef FEAT_GUI
116 pSaveInst(
117#ifdef __MINGW32__
118 GetModuleHandle(NULL)
119#else
120 hInstance
121#endif
122 );
123#endif
124 pmain(argc, argv);
125
126#ifdef VIMDLL
127 FreeLibrary(hLib);
128errout:
129#endif
130 free(argv);
Bram Moolenaar12806c82008-11-12 12:36:30 +0000131 if (tofree != NULL)
132 free(tofree);
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +0000133 free_cmd_argsW();
Bram Moolenaar071d4272004-06-13 20:20:40 +0000134
135 return 0;
136}
137#endif