blob: e37873b760a65bd7fc5e634f1051085062196b1b [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001/* 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 <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
30 __ARGS((int argc, char **argv));
31int (_cdecl *pmain)(int, char **);
32
33#ifndef PROTO
34#ifdef FEAT_GUI
35#ifndef VIMDLL
36void _cdecl SaveInst(HINSTANCE hInst);
37#endif
38void (_cdecl *pSaveInst)(HINSTANCE);
39#endif
40
41 int WINAPI
42WinMain(
43 HINSTANCE hInstance,
44 HINSTANCE hPrevInst,
45 LPSTR lpszCmdLine,
46 int nCmdShow)
47{
48 int argc;
49 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
61 /* Separate the command line into arguments. */
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);
129errout:
130#endif
131 free(argv);
132 free(tofree);
133
134 return 0;
135}
136#endif