1 /* vi:set ts=8 sts=4 sw=4 noet: 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 (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 int WINAPI 42 WinMain( 43 HINSTANCE hInstance UNUSED, 44 HINSTANCE hPrevInst UNUSED, 45 LPSTR lpszCmdLine, 46 int nCmdShow UNUSED) 47 { 48 int argc = 0; 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 argc = get_cmd_args(prog, (char *)lpszCmdLine, &argv, &tofree); 62 if (argc == 0) 63 { 64 MessageBox(0, "Could not allocate memory for command line.", 65 "VIM Error", 0); 66 return 0; 67 } 68 69 #ifdef DYNAMIC_GETTEXT 70 /* Initialize gettext library */ 71 dyn_libintl_init(); 72 #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); 128 errout: 129 #endif 130 free(argv); 131 if (tofree != NULL) 132 free(tofree); 133 free_cmd_argsW(); 134 135 return 0; 136 } 137 #endif 138