blob: d3ac092b41fcec535f2278c182f0b9674f841c54 [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 *
Bram Moolenaar760285d2019-03-27 21:59:45 +010013 * Ron Aaron <ronaharon@yahoo.com> wrote this and the DLL support code.
Bram Moolenaar071d4272004-06-13 20:20:40 +000014 */
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
Bram Moolenaar4f974752019-02-17 17:44:42 +010025#if defined(FEAT_GUI_MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +000026VimMain
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 Moolenaar760285d2019-03-27 21:59:45 +010045 LPSTR lpszCmdLine UNUSED,
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 Moolenaar760285d2019-03-27 21:59:45 +010049 char **argv = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000050#ifdef VIMDLL
Bram Moolenaar760285d2019-03-27 21:59:45 +010051 char prog[256];
Bram Moolenaar071d4272004-06-13 20:20:40 +000052 char *p;
53 HANDLE hLib;
Bram Moolenaar071d4272004-06-13 20:20:40 +000054
55 /* Ron: added full path name so that the $VIM variable will get set to our
56 * startup path (so the .vimrc file can be found w/o a VIM env. var.) */
57 GetModuleFileName(NULL, prog, 255);
58
Bram Moolenaar760285d2019-03-27 21:59:45 +010059# ifdef DYNAMIC_GETTEXT
Bram Moolenaar071d4272004-06-13 20:20:40 +000060 /* Initialize gettext library */
Bram Moolenaar286eacd2016-01-16 18:05:50 +010061 dyn_libintl_init();
Bram Moolenaar760285d2019-03-27 21:59:45 +010062# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000063
Bram Moolenaar071d4272004-06-13 20:20:40 +000064 // LoadLibrary - get name of dll to load in here:
65 p = strrchr(prog, '\\');
66 if (p != NULL)
67 {
68# ifdef DEBUG
69 strcpy(p+1, "vim32d.dll");
70# else
71 strcpy(p+1, "vim32.dll");
72# endif
73 }
74 hLib = LoadLibrary(prog);
75 if (hLib == NULL)
76 {
77 MessageBox(0, _("Could not load vim32.dll!"), _("VIM Error"), 0);
78 goto errout;
79 }
80 // fix up the function pointers
81# ifdef FEAT_GUI
82 pSaveInst = GetProcAddress(hLib, (LPCSTR)2);
83# endif
84 pmain = GetProcAddress(hLib, (LPCSTR)1);
85 if (pmain == NULL)
86 {
87 MessageBox(0, _("Could not fix up function pointers to the DLL!"),
88 _("VIM Error"),0);
89 goto errout;
90 }
91#else
92# ifdef FEAT_GUI
93 pSaveInst = SaveInst;
94# endif
95 pmain =
Bram Moolenaar4f974752019-02-17 17:44:42 +010096# if defined(FEAT_GUI_MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +000097 //&& defined(__MINGW32__)
98 VimMain
99# else
100 main
101# endif
102 ;
103#endif
104#ifdef FEAT_GUI
105 pSaveInst(
106#ifdef __MINGW32__
107 GetModuleHandle(NULL)
108#else
109 hInstance
110#endif
111 );
112#endif
113 pmain(argc, argv);
114
115#ifdef VIMDLL
116 FreeLibrary(hLib);
117errout:
118#endif
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +0000119 free_cmd_argsW();
Bram Moolenaar071d4272004-06-13 20:20:40 +0000120
121 return 0;
122}
123#endif