annotate src/GvimExt/gvimext.cpp @ 31817:a98ef841fd01 v9.0.1241

patch 9.0.1241: Coverity warns for not checking function return value Commit: https://github.com/vim/vim/commit/b58201035060d223d4d795ef9c3bc6b171eee9af Author: Bram Moolenaar <Bram@vim.org> Date: Wed Jan 25 12:27:13 2023 +0000 patch 9.0.1241: Coverity warns for not checking function return value Problem: Coverity warns for not checking function return value. Solution: Explicitly ignore the return value.
author Bram Moolenaar <Bram@vim.org>
date Wed, 25 Jan 2023 13:30:04 +0100
parents 64dac9ff015e
children 32c9b7396a75
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4:
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
2 *
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
3 * VIM - Vi IMproved gvimext by Tianmiao Hu
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
4 *
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
7 */
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
8
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
9 /*
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
10 * gvimext is a DLL which is used for the "Edit with Vim" context menu
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
11 * extension. It implements a MS defined interface with the Shell.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
12 *
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
13 * If you have any questions or any suggestions concerning gvimext, please
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
14 * contact Tianmiao Hu: tianmiao@acm.org.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
15 */
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
16
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
17 #include "gvimext.h"
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
18
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
19 static char *searchpath(char *name);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
20
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
21 // Always get an error while putting the following stuff to the
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
22 // gvimext.h file as class protected variables, give up and
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
23 // declare them as global stuff
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
24 FORMATETC fmte = {CF_HDROP,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
25 (DVTARGETDEVICE FAR *)NULL,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
26 DVASPECT_CONTENT,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
27 -1,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
28 TYMED_HGLOBAL
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
29 };
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
30 STGMEDIUM medium;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
31 HRESULT hres = 0;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
32 UINT cbFiles = 0;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
33
12626
aca41efd888c patch 8.0.1191: MS-Windows: missing 32 and 64 bit files in installer
Christian Brabandt <cb@256bit.org>
parents: 8180
diff changeset
34 /* The buffers size used to be MAX_PATH (260 bytes), but that's not always
415
165c628aa9fc updated for version 7.0108
vimboss
parents: 26
diff changeset
35 * enough */
165c628aa9fc updated for version 7.0108
vimboss
parents: 26
diff changeset
36 #define BUFSIZE 1100
165c628aa9fc updated for version 7.0108
vimboss
parents: 26
diff changeset
37
25413
ee2808fb1be9 patch 8.2.3243: MS-Windows: "edit with multiple Vim" choice is less useful
Bram Moolenaar <Bram@vim.org>
parents: 22924
diff changeset
38 // The "Edit with Vim" shell extension provides these choices when
ee2808fb1be9 patch 8.2.3243: MS-Windows: "edit with multiple Vim" choice is less useful
Bram Moolenaar <Bram@vim.org>
parents: 22924
diff changeset
39 // a new instance of Gvim is selected:
ee2808fb1be9 patch 8.2.3243: MS-Windows: "edit with multiple Vim" choice is less useful
Bram Moolenaar <Bram@vim.org>
parents: 22924
diff changeset
40 // - use tabpages
ee2808fb1be9 patch 8.2.3243: MS-Windows: "edit with multiple Vim" choice is less useful
Bram Moolenaar <Bram@vim.org>
parents: 22924
diff changeset
41 // - enable diff mode
ee2808fb1be9 patch 8.2.3243: MS-Windows: "edit with multiple Vim" choice is less useful
Bram Moolenaar <Bram@vim.org>
parents: 22924
diff changeset
42 // - none of the above
ee2808fb1be9 patch 8.2.3243: MS-Windows: "edit with multiple Vim" choice is less useful
Bram Moolenaar <Bram@vim.org>
parents: 22924
diff changeset
43 #define EDIT_WITH_VIM_USE_TABPAGES (2)
ee2808fb1be9 patch 8.2.3243: MS-Windows: "edit with multiple Vim" choice is less useful
Bram Moolenaar <Bram@vim.org>
parents: 22924
diff changeset
44 #define EDIT_WITH_VIM_IN_DIFF_MODE (1)
ee2808fb1be9 patch 8.2.3243: MS-Windows: "edit with multiple Vim" choice is less useful
Bram Moolenaar <Bram@vim.org>
parents: 22924
diff changeset
45 #define EDIT_WITH_VIM_NO_OPTIONS (0)
ee2808fb1be9 patch 8.2.3243: MS-Windows: "edit with multiple Vim" choice is less useful
Bram Moolenaar <Bram@vim.org>
parents: 22924
diff changeset
46
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
47 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
48 // Get the name of the Gvim executable to use, with the path.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
49 // When "runtime" is non-zero, we were called to find the runtime directory.
415
165c628aa9fc updated for version 7.0108
vimboss
parents: 26
diff changeset
50 // Returns the path in name[BUFSIZE]. It's empty when it fails.
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
51 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
52 static void
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
53 getGvimName(char *name, int runtime)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
54 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
55 HKEY keyhandle;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
56 DWORD hlen;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
57
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
58 // Get the location of gvim from the registry.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
59 name[0] = 0;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
60 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Vim\\Gvim", 0,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
61 KEY_READ, &keyhandle) == ERROR_SUCCESS)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
62 {
415
165c628aa9fc updated for version 7.0108
vimboss
parents: 26
diff changeset
63 hlen = BUFSIZE;
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
64 if (RegQueryValueEx(keyhandle, "path", 0, NULL, (BYTE *)name, &hlen)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
65 != ERROR_SUCCESS)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
66 name[0] = 0;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
67 else
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
68 name[hlen] = 0;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
69 RegCloseKey(keyhandle);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
70 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
71
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
72 // Registry didn't work, use the search path.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
73 if (name[0] == 0)
1366
7e7da11555d2 updated for version 7.1-080
vimboss
parents: 1226
diff changeset
74 strcpy(name, searchpath((char *)"gvim.exe"));
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
75
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
76 if (!runtime)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
77 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
78 // Only when looking for the executable, not the runtime dir, we can
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
79 // search for the batch file or a name without a path.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
80 if (name[0] == 0)
1366
7e7da11555d2 updated for version 7.1-080
vimboss
parents: 1226
diff changeset
81 strcpy(name, searchpath((char *)"gvim.bat"));
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
82 if (name[0] == 0)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
83 strcpy(name, "gvim"); // finds gvim.bat or gvim.exe
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
84 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
85 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
86
2295
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
87 static void
6805
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
88 getGvimInvocation(char *name, int runtime)
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
89 {
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
90 getGvimName(name, runtime);
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
91 // avoid that Vim tries to expand wildcards in the file names
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
92 strcat(name, " --literal");
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
93 }
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
94
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
95 static void
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
96 getGvimInvocationW(wchar_t *nameW)
2295
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
97 {
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
98 char *name;
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
99
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
100 name = (char *)malloc(BUFSIZE);
6805
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
101 getGvimInvocation(name, 0);
2295
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
102 mbstowcs(nameW, name, BUFSIZE);
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
103 free(name);
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
104 }
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
105
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
106 //
415
165c628aa9fc updated for version 7.0108
vimboss
parents: 26
diff changeset
107 // Get the Vim runtime directory into buf[BUFSIZE].
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
108 // The result is empty when it failed.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
109 // When it works, the path ends in a slash or backslash.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
110 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
111 static void
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
112 getRuntimeDir(char *buf)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
113 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
114 int idx;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
115
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
116 getGvimName(buf, 1);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
117 if (buf[0] != 0)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
118 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
119 // When no path found, use the search path to expand it.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
120 if (strchr(buf, '/') == NULL && strchr(buf, '\\') == NULL)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
121 strcpy(buf, searchpath(buf));
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
122
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
123 // remove "gvim.exe" from the end
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 415
diff changeset
124 for (idx = (int)strlen(buf) - 1; idx >= 0; idx--)
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
125 if (buf[idx] == '\\' || buf[idx] == '/')
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
126 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
127 buf[idx + 1] = 0;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
128 break;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
129 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
130 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
131 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
132
6805
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
133 HBITMAP IconToBitmap(HICON hIcon, HBRUSH hBackground, int width, int height)
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
134 {
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
135 HDC hDC = GetDC(NULL);
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
136 HDC hMemDC = CreateCompatibleDC(hDC);
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
137 HBITMAP hMemBmp = CreateCompatibleBitmap(hDC, width, height);
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
138 HBITMAP hResultBmp = NULL;
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
139 HGDIOBJ hOrgBMP = SelectObject(hMemDC, hMemBmp);
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
140
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
141 DrawIconEx(hMemDC, 0, 0, hIcon, width, height, 0, hBackground, DI_NORMAL);
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
142
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
143 hResultBmp = hMemBmp;
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
144 hMemBmp = NULL;
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
145
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
146 SelectObject(hMemDC, hOrgBMP);
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
147 DeleteDC(hMemDC);
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
148 ReleaseDC(NULL, hDC);
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
149 DestroyIcon(hIcon);
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
150 return hResultBmp;
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
151 }
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
152
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
153 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
154 // GETTEXT: translated messages and menu entries
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
155 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
156 #ifndef FEAT_GETTEXT
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
157 # define _(x) x
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
158 #else
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
159 # define _(x) (*dyn_libintl_gettext)(x)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
160 # define VIMPACKAGE "vim"
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
161 # ifndef GETTEXT_DLL
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
162 # define GETTEXT_DLL "libintl.dll"
8180
1e48ffa2d697 commit https://github.com/vim/vim/commit/271273c39f2150ecdaa67fe1a2a8e9cdc63db545
Christian Brabandt <cb@256bit.org>
parents: 6805
diff changeset
163 # define GETTEXT_DLL_ALT "libintl-8.dll"
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
164 # endif
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
165
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
166 // Dummy functions
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
167 static char *null_libintl_gettext(const char *);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
168 static char *null_libintl_textdomain(const char *);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
169 static char *null_libintl_bindtextdomain(const char *, const char *);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
170 static int dyn_libintl_init(char *dir);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
171 static void dyn_libintl_end(void);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
172
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
173 static HINSTANCE hLibintlDLL = 0;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
174 static char *(*dyn_libintl_gettext)(const char *) = null_libintl_gettext;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
175 static char *(*dyn_libintl_textdomain)(const char *) = null_libintl_textdomain;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
176 static char *(*dyn_libintl_bindtextdomain)(const char *, const char *)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
177 = null_libintl_bindtextdomain;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
178
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
179 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
180 // Attempt to load libintl.dll. If it doesn't work, use dummy functions.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
181 // "dir" is the directory where the libintl.dll might be.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
182 // Return 1 for success, 0 for failure.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
183 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
184 static int
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
185 dyn_libintl_init(char *dir)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
186 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
187 int i;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
188 static struct
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
189 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
190 char *name;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
191 FARPROC *ptr;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
192 } libintl_entry[] =
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
193 {
1366
7e7da11555d2 updated for version 7.1-080
vimboss
parents: 1226
diff changeset
194 {(char *)"gettext", (FARPROC*)&dyn_libintl_gettext},
7e7da11555d2 updated for version 7.1-080
vimboss
parents: 1226
diff changeset
195 {(char *)"textdomain", (FARPROC*)&dyn_libintl_textdomain},
7e7da11555d2 updated for version 7.1-080
vimboss
parents: 1226
diff changeset
196 {(char *)"bindtextdomain", (FARPROC*)&dyn_libintl_bindtextdomain},
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
197 {NULL, NULL}
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
198 };
8180
1e48ffa2d697 commit https://github.com/vim/vim/commit/271273c39f2150ecdaa67fe1a2a8e9cdc63db545
Christian Brabandt <cb@256bit.org>
parents: 6805
diff changeset
199 DWORD len, len2;
1e48ffa2d697 commit https://github.com/vim/vim/commit/271273c39f2150ecdaa67fe1a2a8e9cdc63db545
Christian Brabandt <cb@256bit.org>
parents: 6805
diff changeset
200 LPWSTR buf = NULL;
1e48ffa2d697 commit https://github.com/vim/vim/commit/271273c39f2150ecdaa67fe1a2a8e9cdc63db545
Christian Brabandt <cb@256bit.org>
parents: 6805
diff changeset
201 LPWSTR buf2 = NULL;
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
202
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
203 // No need to initialize twice.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
204 if (hLibintlDLL)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
205 return 1;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
206
12626
aca41efd888c patch 8.0.1191: MS-Windows: missing 32 and 64 bit files in installer
Christian Brabandt <cb@256bit.org>
parents: 8180
diff changeset
207 // Load gettext library from $VIMRUNTIME\GvimExt{64,32} directory.
8180
1e48ffa2d697 commit https://github.com/vim/vim/commit/271273c39f2150ecdaa67fe1a2a8e9cdc63db545
Christian Brabandt <cb@256bit.org>
parents: 6805
diff changeset
208 // Add the directory to $PATH temporarily.
1e48ffa2d697 commit https://github.com/vim/vim/commit/271273c39f2150ecdaa67fe1a2a8e9cdc63db545
Christian Brabandt <cb@256bit.org>
parents: 6805
diff changeset
209 len = GetEnvironmentVariableW(L"PATH", NULL, 0);
1e48ffa2d697 commit https://github.com/vim/vim/commit/271273c39f2150ecdaa67fe1a2a8e9cdc63db545
Christian Brabandt <cb@256bit.org>
parents: 6805
diff changeset
210 len2 = MAX_PATH + 1 + len;
1e48ffa2d697 commit https://github.com/vim/vim/commit/271273c39f2150ecdaa67fe1a2a8e9cdc63db545
Christian Brabandt <cb@256bit.org>
parents: 6805
diff changeset
211 buf = (LPWSTR)malloc(len * sizeof(WCHAR));
1e48ffa2d697 commit https://github.com/vim/vim/commit/271273c39f2150ecdaa67fe1a2a8e9cdc63db545
Christian Brabandt <cb@256bit.org>
parents: 6805
diff changeset
212 buf2 = (LPWSTR)malloc(len2 * sizeof(WCHAR));
1e48ffa2d697 commit https://github.com/vim/vim/commit/271273c39f2150ecdaa67fe1a2a8e9cdc63db545
Christian Brabandt <cb@256bit.org>
parents: 6805
diff changeset
213 if (buf != NULL && buf2 != NULL)
1e48ffa2d697 commit https://github.com/vim/vim/commit/271273c39f2150ecdaa67fe1a2a8e9cdc63db545
Christian Brabandt <cb@256bit.org>
parents: 6805
diff changeset
214 {
1e48ffa2d697 commit https://github.com/vim/vim/commit/271273c39f2150ecdaa67fe1a2a8e9cdc63db545
Christian Brabandt <cb@256bit.org>
parents: 6805
diff changeset
215 GetEnvironmentVariableW(L"PATH", buf, len);
22924
db65bb242582 patch 8.2.2009: MS-Windows: setting $LANG in gvimext only causes problems
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
216 # ifdef _WIN64
12626
aca41efd888c patch 8.0.1191: MS-Windows: missing 32 and 64 bit files in installer
Christian Brabandt <cb@256bit.org>
parents: 8180
diff changeset
217 _snwprintf(buf2, len2, L"%S\\GvimExt64;%s", dir, buf);
22924
db65bb242582 patch 8.2.2009: MS-Windows: setting $LANG in gvimext only causes problems
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
218 # else
12626
aca41efd888c patch 8.0.1191: MS-Windows: missing 32 and 64 bit files in installer
Christian Brabandt <cb@256bit.org>
parents: 8180
diff changeset
219 _snwprintf(buf2, len2, L"%S\\GvimExt32;%s", dir, buf);
22924
db65bb242582 patch 8.2.2009: MS-Windows: setting $LANG in gvimext only causes problems
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
220 # endif
8180
1e48ffa2d697 commit https://github.com/vim/vim/commit/271273c39f2150ecdaa67fe1a2a8e9cdc63db545
Christian Brabandt <cb@256bit.org>
parents: 6805
diff changeset
221 SetEnvironmentVariableW(L"PATH", buf2);
1e48ffa2d697 commit https://github.com/vim/vim/commit/271273c39f2150ecdaa67fe1a2a8e9cdc63db545
Christian Brabandt <cb@256bit.org>
parents: 6805
diff changeset
222 hLibintlDLL = LoadLibrary(GETTEXT_DLL);
22924
db65bb242582 patch 8.2.2009: MS-Windows: setting $LANG in gvimext only causes problems
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
223 # ifdef GETTEXT_DLL_ALT
8180
1e48ffa2d697 commit https://github.com/vim/vim/commit/271273c39f2150ecdaa67fe1a2a8e9cdc63db545
Christian Brabandt <cb@256bit.org>
parents: 6805
diff changeset
224 if (!hLibintlDLL)
1e48ffa2d697 commit https://github.com/vim/vim/commit/271273c39f2150ecdaa67fe1a2a8e9cdc63db545
Christian Brabandt <cb@256bit.org>
parents: 6805
diff changeset
225 hLibintlDLL = LoadLibrary(GETTEXT_DLL_ALT);
22924
db65bb242582 patch 8.2.2009: MS-Windows: setting $LANG in gvimext only causes problems
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
226 # endif
8180
1e48ffa2d697 commit https://github.com/vim/vim/commit/271273c39f2150ecdaa67fe1a2a8e9cdc63db545
Christian Brabandt <cb@256bit.org>
parents: 6805
diff changeset
227 SetEnvironmentVariableW(L"PATH", buf);
1e48ffa2d697 commit https://github.com/vim/vim/commit/271273c39f2150ecdaa67fe1a2a8e9cdc63db545
Christian Brabandt <cb@256bit.org>
parents: 6805
diff changeset
228 }
1e48ffa2d697 commit https://github.com/vim/vim/commit/271273c39f2150ecdaa67fe1a2a8e9cdc63db545
Christian Brabandt <cb@256bit.org>
parents: 6805
diff changeset
229 free(buf);
1e48ffa2d697 commit https://github.com/vim/vim/commit/271273c39f2150ecdaa67fe1a2a8e9cdc63db545
Christian Brabandt <cb@256bit.org>
parents: 6805
diff changeset
230 free(buf2);
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
231 if (!hLibintlDLL)
8180
1e48ffa2d697 commit https://github.com/vim/vim/commit/271273c39f2150ecdaa67fe1a2a8e9cdc63db545
Christian Brabandt <cb@256bit.org>
parents: 6805
diff changeset
232 return 0;
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
233
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
234 // Get the addresses of the functions we need.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
235 for (i = 0; libintl_entry[i].name != NULL
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
236 && libintl_entry[i].ptr != NULL; ++i)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
237 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
238 if ((*libintl_entry[i].ptr = GetProcAddress(hLibintlDLL,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
239 libintl_entry[i].name)) == NULL)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
240 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
241 dyn_libintl_end();
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
242 return 0;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
243 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
244 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
245 return 1;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
246 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
247
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
248 static void
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
249 dyn_libintl_end(void)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
250 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
251 if (hLibintlDLL)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
252 FreeLibrary(hLibintlDLL);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
253 hLibintlDLL = NULL;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
254 dyn_libintl_gettext = null_libintl_gettext;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
255 dyn_libintl_textdomain = null_libintl_textdomain;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
256 dyn_libintl_bindtextdomain = null_libintl_bindtextdomain;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
257 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
258
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
259 static char *
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
260 null_libintl_gettext(const char *msgid)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
261 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
262 return (char *)msgid;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
263 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
264
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
265 static char *
1686
c7c53db66b55 updated for version 7.2b-019
vimboss
parents: 1366
diff changeset
266 null_libintl_bindtextdomain(const char * /* domainname */, const char * /* dirname */)
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
267 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
268 return NULL;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
269 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
270
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
271 static char *
1686
c7c53db66b55 updated for version 7.2b-019
vimboss
parents: 1366
diff changeset
272 null_libintl_textdomain(const char* /* domainname */)
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
273 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
274 return NULL;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
275 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
276
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
277 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
278 // Setup for translating strings.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
279 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
280 static void
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
281 dyn_gettext_load(void)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
282 {
415
165c628aa9fc updated for version 7.0108
vimboss
parents: 26
diff changeset
283 char szBuff[BUFSIZE];
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
284 DWORD len;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
285
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
286 // Try to locate the runtime files. The path is used to find libintl.dll
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
287 // and the vim.mo files.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
288 getRuntimeDir(szBuff);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
289 if (szBuff[0] != 0)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
290 {
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 415
diff changeset
291 len = (DWORD)strlen(szBuff);
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
292 if (dyn_libintl_init(szBuff))
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
293 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
294 strcpy(szBuff + len, "lang");
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
295
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
296 (*dyn_libintl_bindtextdomain)(VIMPACKAGE, szBuff);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
297 (*dyn_libintl_textdomain)(VIMPACKAGE);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
298 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
299 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
300 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
301
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
302 static void
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
303 dyn_gettext_free(void)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
304 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
305 dyn_libintl_end();
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
306 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
307 #endif // FEAT_GETTEXT
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
308
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
309 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
310 // Global variables
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
311 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
312 UINT g_cRefThisDll = 0; // Reference count of this DLL.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
313 HINSTANCE g_hmodThisDll = NULL; // Handle to this DLL itself.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
314
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
315
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
316 //---------------------------------------------------------------------------
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
317 // DllMain
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
318 //---------------------------------------------------------------------------
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
319 extern "C" int APIENTRY
1686
c7c53db66b55 updated for version 7.2b-019
vimboss
parents: 1366
diff changeset
320 DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /* lpReserved */)
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
321 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
322 switch (dwReason)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
323 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
324 case DLL_PROCESS_ATTACH:
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
325 // Extension DLL one-time initialization
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
326 g_hmodThisDll = hInstance;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
327 break;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
328
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
329 case DLL_PROCESS_DETACH:
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
330 break;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
331 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
332
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
333 return 1; // ok
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
334 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
335
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
336 static void
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
337 inc_cRefThisDLL()
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
338 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
339 #ifdef FEAT_GETTEXT
22924
db65bb242582 patch 8.2.2009: MS-Windows: setting $LANG in gvimext only causes problems
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
340 if (g_cRefThisDll == 0)
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
341 dyn_gettext_load();
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
342 #endif
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
343 InterlockedIncrement((LPLONG)&g_cRefThisDll);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
344 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
345
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
346 static void
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
347 dec_cRefThisDLL()
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
348 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
349 #ifdef FEAT_GETTEXT
22924
db65bb242582 patch 8.2.2009: MS-Windows: setting $LANG in gvimext only causes problems
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
350 if (InterlockedDecrement((LPLONG)&g_cRefThisDll) == 0)
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
351 dyn_gettext_free();
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
352 #else
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
353 InterlockedDecrement((LPLONG)&g_cRefThisDll);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
354 #endif
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
355 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
356
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
357 //---------------------------------------------------------------------------
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
358 // DllCanUnloadNow
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
359 //---------------------------------------------------------------------------
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
360
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
361 STDAPI DllCanUnloadNow(void)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
362 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
363 return (g_cRefThisDll == 0 ? S_OK : S_FALSE);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
364 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
365
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
366 STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppvOut)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
367 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
368 *ppvOut = NULL;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
369
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
370 if (IsEqualIID(rclsid, CLSID_ShellExtension))
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
371 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
372 CShellExtClassFactory *pcf = new CShellExtClassFactory;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
373
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
374 return pcf->QueryInterface(riid, ppvOut);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
375 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
376
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
377 return CLASS_E_CLASSNOTAVAILABLE;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
378 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
379
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
380 CShellExtClassFactory::CShellExtClassFactory()
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
381 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
382 m_cRef = 0L;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
383
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
384 inc_cRefThisDLL();
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
385 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
386
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
387 CShellExtClassFactory::~CShellExtClassFactory()
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
388 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
389 dec_cRefThisDLL();
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
390 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
391
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
392 STDMETHODIMP CShellExtClassFactory::QueryInterface(REFIID riid,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
393 LPVOID FAR *ppv)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
394 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
395 *ppv = NULL;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
396
6805
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
397 // any interface on this object is the object pointer
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
398
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
399 if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IClassFactory))
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
400 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
401 *ppv = (LPCLASSFACTORY)this;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
402
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
403 AddRef();
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
404
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
405 return NOERROR;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
406 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
407
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
408 return E_NOINTERFACE;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
409 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
410
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
411 STDMETHODIMP_(ULONG) CShellExtClassFactory::AddRef()
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
412 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
413 return InterlockedIncrement((LPLONG)&m_cRef);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
414 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
415
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
416 STDMETHODIMP_(ULONG) CShellExtClassFactory::Release()
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
417 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
418 if (InterlockedDecrement((LPLONG)&m_cRef))
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
419 return m_cRef;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
420
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
421 delete this;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
422
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
423 return 0L;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
424 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
425
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
426 STDMETHODIMP CShellExtClassFactory::CreateInstance(LPUNKNOWN pUnkOuter,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
427 REFIID riid,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
428 LPVOID *ppvObj)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
429 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
430 *ppvObj = NULL;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
431
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
432 // Shell extensions typically don't support aggregation (inheritance)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
433
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
434 if (pUnkOuter)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
435 return CLASS_E_NOAGGREGATION;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
436
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
437 // Create the main shell extension object. The shell will then call
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
438 // QueryInterface with IID_IShellExtInit--this is how shell extensions are
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
439 // initialized.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
440
6805
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
441 LPCSHELLEXT pShellExt = new CShellExt(); // create the CShellExt object
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
442
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
443 if (NULL == pShellExt)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
444 return E_OUTOFMEMORY;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
445
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
446 return pShellExt->QueryInterface(riid, ppvObj);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
447 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
448
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
449
1686
c7c53db66b55 updated for version 7.2b-019
vimboss
parents: 1366
diff changeset
450 STDMETHODIMP CShellExtClassFactory::LockServer(BOOL /* fLock */)
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
451 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
452 return NOERROR;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
453 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
454
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
455 // *********************** CShellExt *************************
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
456 CShellExt::CShellExt()
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
457 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
458 m_cRef = 0L;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
459 m_pDataObj = NULL;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
460
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
461 inc_cRefThisDLL();
6805
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
462
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
463 LoadMenuIcon();
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
464 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
465
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
466 CShellExt::~CShellExt()
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
467 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
468 if (m_pDataObj)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
469 m_pDataObj->Release();
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
470
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
471 dec_cRefThisDLL();
6805
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
472
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
473 if (m_hVimIconBitmap)
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
474 DeleteObject(m_hVimIconBitmap);
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
475 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
476
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
477 STDMETHODIMP CShellExt::QueryInterface(REFIID riid, LPVOID FAR *ppv)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
478 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
479 *ppv = NULL;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
480
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
481 if (IsEqualIID(riid, IID_IShellExtInit) || IsEqualIID(riid, IID_IUnknown))
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
482 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
483 *ppv = (LPSHELLEXTINIT)this;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
484 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
485 else if (IsEqualIID(riid, IID_IContextMenu))
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
486 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
487 *ppv = (LPCONTEXTMENU)this;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
488 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
489
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
490 if (*ppv)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
491 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
492 AddRef();
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
493
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
494 return NOERROR;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
495 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
496
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
497 return E_NOINTERFACE;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
498 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
499
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
500 STDMETHODIMP_(ULONG) CShellExt::AddRef()
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
501 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
502 return InterlockedIncrement((LPLONG)&m_cRef);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
503 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
504
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
505 STDMETHODIMP_(ULONG) CShellExt::Release()
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
506 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
507
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
508 if (InterlockedDecrement((LPLONG)&m_cRef))
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
509 return m_cRef;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
510
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
511 delete this;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
512
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
513 return 0L;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
514 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
515
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
516
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
517 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
518 // FUNCTION: CShellExt::Initialize(LPCITEMIDLIST, LPDATAOBJECT, HKEY)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
519 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
520 // PURPOSE: Called by the shell when initializing a context menu or property
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
521 // sheet extension.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
522 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
523 // PARAMETERS:
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
524 // pIDFolder - Specifies the parent folder
4352
04736b4030ec updated for version 7.3.925
Bram Moolenaar <bram@vim.org>
parents: 3008
diff changeset
525 // pDataObj - Specifies the set of items selected in that folder.
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
526 // hRegKey - Specifies the type of the focused item in the selection.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
527 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
528 // RETURN VALUE:
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
529 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
530 // NOERROR in all cases.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
531 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
532 // COMMENTS: Note that at the time this function is called, we don't know
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
533 // (or care) what type of shell extension is being initialized.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
534 // It could be a context menu or a property sheet.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
535 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
536
1686
c7c53db66b55 updated for version 7.2b-019
vimboss
parents: 1366
diff changeset
537 STDMETHODIMP CShellExt::Initialize(LPCITEMIDLIST /* pIDFolder */,
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
538 LPDATAOBJECT pDataObj,
1686
c7c53db66b55 updated for version 7.2b-019
vimboss
parents: 1366
diff changeset
539 HKEY /* hRegKey */)
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
540 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
541 // Initialize can be called more than once
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
542 if (m_pDataObj)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
543 m_pDataObj->Release();
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
544
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
545 // duplicate the object pointer and registry handle
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
546
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
547 if (pDataObj)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
548 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
549 m_pDataObj = pDataObj;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
550 pDataObj->AddRef();
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
551 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
552
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
553 return NOERROR;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
554 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
555
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
556
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
557 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
558 // FUNCTION: CShellExt::QueryContextMenu(HMENU, UINT, UINT, UINT, UINT)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
559 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
560 // PURPOSE: Called by the shell just before the context menu is displayed.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
561 // This is where you add your specific menu items.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
562 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
563 // PARAMETERS:
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
564 // hMenu - Handle to the context menu
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
565 // indexMenu - Index of where to begin inserting menu items
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
566 // idCmdFirst - Lowest value for new menu ID's
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
567 // idCmtLast - Highest value for new menu ID's
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
568 // uFlags - Specifies the context of the menu event
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
569 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
570 // RETURN VALUE:
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
571 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
572 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
573 // COMMENTS:
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
574 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
575
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
576 STDMETHODIMP CShellExt::QueryContextMenu(HMENU hMenu,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
577 UINT indexMenu,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
578 UINT idCmdFirst,
1686
c7c53db66b55 updated for version 7.2b-019
vimboss
parents: 1366
diff changeset
579 UINT /* idCmdLast */,
c7c53db66b55 updated for version 7.2b-019
vimboss
parents: 1366
diff changeset
580 UINT /* uFlags */)
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
581 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
582 UINT idCmd = idCmdFirst;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
583
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
584 hres = m_pDataObj->GetData(&fmte, &medium);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
585 if (medium.hGlobal)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
586 cbFiles = DragQueryFile((HDROP)medium.hGlobal, (UINT)-1, 0, 0);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
587
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
588 // InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
589
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
590 // Initialize m_cntOfHWnd to 0
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
591 m_cntOfHWnd = 0;
2972
bdc3335bd72e updated for version 7.3.258
Bram Moolenaar <bram@vim.org>
parents: 2295
diff changeset
592
bdc3335bd72e updated for version 7.3.258
Bram Moolenaar <bram@vim.org>
parents: 2295
diff changeset
593 HKEY keyhandle;
bdc3335bd72e updated for version 7.3.258
Bram Moolenaar <bram@vim.org>
parents: 2295
diff changeset
594 bool showExisting = true;
6805
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
595 bool showIcons = true;
2972
bdc3335bd72e updated for version 7.3.258
Bram Moolenaar <bram@vim.org>
parents: 2295
diff changeset
596
bdc3335bd72e updated for version 7.3.258
Bram Moolenaar <bram@vim.org>
parents: 2295
diff changeset
597 // Check whether "Edit with existing Vim" entries are disabled.
bdc3335bd72e updated for version 7.3.258
Bram Moolenaar <bram@vim.org>
parents: 2295
diff changeset
598 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Vim\\Gvim", 0,
bdc3335bd72e updated for version 7.3.258
Bram Moolenaar <bram@vim.org>
parents: 2295
diff changeset
599 KEY_READ, &keyhandle) == ERROR_SUCCESS)
bdc3335bd72e updated for version 7.3.258
Bram Moolenaar <bram@vim.org>
parents: 2295
diff changeset
600 {
bdc3335bd72e updated for version 7.3.258
Bram Moolenaar <bram@vim.org>
parents: 2295
diff changeset
601 if (RegQueryValueEx(keyhandle, "DisableEditWithExisting", 0, NULL,
bdc3335bd72e updated for version 7.3.258
Bram Moolenaar <bram@vim.org>
parents: 2295
diff changeset
602 NULL, NULL) == ERROR_SUCCESS)
bdc3335bd72e updated for version 7.3.258
Bram Moolenaar <bram@vim.org>
parents: 2295
diff changeset
603 showExisting = false;
6805
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
604 if (RegQueryValueEx(keyhandle, "DisableContextMenuIcons", 0, NULL,
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
605 NULL, NULL) == ERROR_SUCCESS)
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
606 showIcons = false;
2972
bdc3335bd72e updated for version 7.3.258
Bram Moolenaar <bram@vim.org>
parents: 2295
diff changeset
607 RegCloseKey(keyhandle);
bdc3335bd72e updated for version 7.3.258
Bram Moolenaar <bram@vim.org>
parents: 2295
diff changeset
608 }
bdc3335bd72e updated for version 7.3.258
Bram Moolenaar <bram@vim.org>
parents: 2295
diff changeset
609
bdc3335bd72e updated for version 7.3.258
Bram Moolenaar <bram@vim.org>
parents: 2295
diff changeset
610 // Retrieve all the vim instances, unless disabled.
bdc3335bd72e updated for version 7.3.258
Bram Moolenaar <bram@vim.org>
parents: 2295
diff changeset
611 if (showExisting)
bdc3335bd72e updated for version 7.3.258
Bram Moolenaar <bram@vim.org>
parents: 2295
diff changeset
612 EnumWindows(EnumWindowsProc, (LPARAM)this);
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
613
6805
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
614 MENUITEMINFO mii = { sizeof(MENUITEMINFO) };
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
615 mii.fMask = MIIM_STRING | MIIM_ID;
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
616 if (showIcons)
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
617 {
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
618 mii.fMask |= MIIM_BITMAP;
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
619 mii.hbmpItem = m_hVimIconBitmap;
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
620 }
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
621
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
622 if (cbFiles > 1)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
623 {
6805
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
624 mii.wID = idCmd++;
25413
ee2808fb1be9 patch 8.2.3243: MS-Windows: "edit with multiple Vim" choice is less useful
Bram Moolenaar <Bram@vim.org>
parents: 22924
diff changeset
625 mii.dwTypeData = _("Edit with Vim using &tabpages");
6805
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
626 mii.cch = lstrlen(mii.dwTypeData);
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
627 InsertMenuItem(hMenu, indexMenu++, TRUE, &mii);
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
628
6805
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
629 mii.wID = idCmd++;
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
630 mii.dwTypeData = _("Edit with single &Vim");
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
631 mii.cch = lstrlen(mii.dwTypeData);
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
632 InsertMenuItem(hMenu, indexMenu++, TRUE, &mii);
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
633
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
634 if (cbFiles <= 4)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
635 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
636 // Can edit up to 4 files in diff mode
6805
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
637 mii.wID = idCmd++;
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
638 mii.dwTypeData = _("Diff with Vim");
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
639 mii.cch = lstrlen(mii.dwTypeData);
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
640 InsertMenuItem(hMenu, indexMenu++, TRUE, &mii);
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
641 m_edit_existing_off = 3;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
642 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
643 else
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
644 m_edit_existing_off = 2;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
645
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
646 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
647 else
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
648 {
6805
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
649 mii.wID = idCmd++;
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
650 mii.dwTypeData = _("Edit with &Vim");
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
651 mii.cch = lstrlen(mii.dwTypeData);
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
652 InsertMenuItem(hMenu, indexMenu++, TRUE, &mii);
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
653 m_edit_existing_off = 1;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
654 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
655
14962
013b70517b1a patch 8.1.0492: "Edit with existing Vim" list can get long
Bram Moolenaar <Bram@vim.org>
parents: 12626
diff changeset
656 HMENU hSubMenu = NULL;
013b70517b1a patch 8.1.0492: "Edit with existing Vim" list can get long
Bram Moolenaar <Bram@vim.org>
parents: 12626
diff changeset
657 if (m_cntOfHWnd > 1)
013b70517b1a patch 8.1.0492: "Edit with existing Vim" list can get long
Bram Moolenaar <Bram@vim.org>
parents: 12626
diff changeset
658 {
013b70517b1a patch 8.1.0492: "Edit with existing Vim" list can get long
Bram Moolenaar <Bram@vim.org>
parents: 12626
diff changeset
659 hSubMenu = CreatePopupMenu();
013b70517b1a patch 8.1.0492: "Edit with existing Vim" list can get long
Bram Moolenaar <Bram@vim.org>
parents: 12626
diff changeset
660 mii.fMask |= MIIM_SUBMENU;
013b70517b1a patch 8.1.0492: "Edit with existing Vim" list can get long
Bram Moolenaar <Bram@vim.org>
parents: 12626
diff changeset
661 mii.wID = idCmd;
013b70517b1a patch 8.1.0492: "Edit with existing Vim" list can get long
Bram Moolenaar <Bram@vim.org>
parents: 12626
diff changeset
662 mii.dwTypeData = _("Edit with existing Vim");
013b70517b1a patch 8.1.0492: "Edit with existing Vim" list can get long
Bram Moolenaar <Bram@vim.org>
parents: 12626
diff changeset
663 mii.cch = lstrlen(mii.dwTypeData);
013b70517b1a patch 8.1.0492: "Edit with existing Vim" list can get long
Bram Moolenaar <Bram@vim.org>
parents: 12626
diff changeset
664 mii.hSubMenu = hSubMenu;
013b70517b1a patch 8.1.0492: "Edit with existing Vim" list can get long
Bram Moolenaar <Bram@vim.org>
parents: 12626
diff changeset
665 InsertMenuItem(hMenu, indexMenu++, TRUE, &mii);
013b70517b1a patch 8.1.0492: "Edit with existing Vim" list can get long
Bram Moolenaar <Bram@vim.org>
parents: 12626
diff changeset
666 mii.fMask = mii.fMask & ~MIIM_SUBMENU;
013b70517b1a patch 8.1.0492: "Edit with existing Vim" list can get long
Bram Moolenaar <Bram@vim.org>
parents: 12626
diff changeset
667 mii.hSubMenu = NULL;
013b70517b1a patch 8.1.0492: "Edit with existing Vim" list can get long
Bram Moolenaar <Bram@vim.org>
parents: 12626
diff changeset
668 }
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
669 // Now display all the vim instances
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
670 for (int i = 0; i < m_cntOfHWnd; i++)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
671 {
415
165c628aa9fc updated for version 7.0108
vimboss
parents: 26
diff changeset
672 char title[BUFSIZE];
165c628aa9fc updated for version 7.0108
vimboss
parents: 26
diff changeset
673 char temp[BUFSIZE];
14962
013b70517b1a patch 8.1.0492: "Edit with existing Vim" list can get long
Bram Moolenaar <Bram@vim.org>
parents: 12626
diff changeset
674 int index;
013b70517b1a patch 8.1.0492: "Edit with existing Vim" list can get long
Bram Moolenaar <Bram@vim.org>
parents: 12626
diff changeset
675 HMENU hmenu;
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
676
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
677 // Obtain window title, continue if can not
415
165c628aa9fc updated for version 7.0108
vimboss
parents: 26
diff changeset
678 if (GetWindowText(m_hWnd[i], title, BUFSIZE - 1) == 0)
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
679 continue;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
680 // Truncate the title before the path, keep the file name
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
681 char *pos = strchr(title, '(');
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
682 if (pos != NULL)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
683 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
684 if (pos > title && pos[-1] == ' ')
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
685 --pos;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
686 *pos = 0;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
687 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
688 // Now concatenate
14962
013b70517b1a patch 8.1.0492: "Edit with existing Vim" list can get long
Bram Moolenaar <Bram@vim.org>
parents: 12626
diff changeset
689 if (m_cntOfHWnd > 1)
013b70517b1a patch 8.1.0492: "Edit with existing Vim" list can get long
Bram Moolenaar <Bram@vim.org>
parents: 12626
diff changeset
690 temp[0] = '\0';
013b70517b1a patch 8.1.0492: "Edit with existing Vim" list can get long
Bram Moolenaar <Bram@vim.org>
parents: 12626
diff changeset
691 else
013b70517b1a patch 8.1.0492: "Edit with existing Vim" list can get long
Bram Moolenaar <Bram@vim.org>
parents: 12626
diff changeset
692 {
013b70517b1a patch 8.1.0492: "Edit with existing Vim" list can get long
Bram Moolenaar <Bram@vim.org>
parents: 12626
diff changeset
693 strncpy(temp, _("Edit with existing Vim - "), BUFSIZE - 1);
013b70517b1a patch 8.1.0492: "Edit with existing Vim" list can get long
Bram Moolenaar <Bram@vim.org>
parents: 12626
diff changeset
694 temp[BUFSIZE - 1] = '\0';
013b70517b1a patch 8.1.0492: "Edit with existing Vim" list can get long
Bram Moolenaar <Bram@vim.org>
parents: 12626
diff changeset
695 }
1953
378e33d47ab0 updated for version 7.2-250
vimboss
parents: 1686
diff changeset
696 strncat(temp, title, BUFSIZE - 1 - strlen(temp));
378e33d47ab0 updated for version 7.2-250
vimboss
parents: 1686
diff changeset
697 temp[BUFSIZE - 1] = '\0';
6805
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
698
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
699 mii.wID = idCmd++;
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
700 mii.dwTypeData = temp;
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
701 mii.cch = lstrlen(mii.dwTypeData);
14962
013b70517b1a patch 8.1.0492: "Edit with existing Vim" list can get long
Bram Moolenaar <Bram@vim.org>
parents: 12626
diff changeset
702 if (m_cntOfHWnd > 1)
013b70517b1a patch 8.1.0492: "Edit with existing Vim" list can get long
Bram Moolenaar <Bram@vim.org>
parents: 12626
diff changeset
703 {
013b70517b1a patch 8.1.0492: "Edit with existing Vim" list can get long
Bram Moolenaar <Bram@vim.org>
parents: 12626
diff changeset
704 hmenu = hSubMenu;
013b70517b1a patch 8.1.0492: "Edit with existing Vim" list can get long
Bram Moolenaar <Bram@vim.org>
parents: 12626
diff changeset
705 index = i;
013b70517b1a patch 8.1.0492: "Edit with existing Vim" list can get long
Bram Moolenaar <Bram@vim.org>
parents: 12626
diff changeset
706 }
013b70517b1a patch 8.1.0492: "Edit with existing Vim" list can get long
Bram Moolenaar <Bram@vim.org>
parents: 12626
diff changeset
707 else
013b70517b1a patch 8.1.0492: "Edit with existing Vim" list can get long
Bram Moolenaar <Bram@vim.org>
parents: 12626
diff changeset
708 {
013b70517b1a patch 8.1.0492: "Edit with existing Vim" list can get long
Bram Moolenaar <Bram@vim.org>
parents: 12626
diff changeset
709 hmenu = hMenu;
013b70517b1a patch 8.1.0492: "Edit with existing Vim" list can get long
Bram Moolenaar <Bram@vim.org>
parents: 12626
diff changeset
710 index = indexMenu++;
013b70517b1a patch 8.1.0492: "Edit with existing Vim" list can get long
Bram Moolenaar <Bram@vim.org>
parents: 12626
diff changeset
711 }
013b70517b1a patch 8.1.0492: "Edit with existing Vim" list can get long
Bram Moolenaar <Bram@vim.org>
parents: 12626
diff changeset
712 InsertMenuItem(hmenu, index, TRUE, &mii);
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
713 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
714 // InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
715
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
716 // Must return number of menu items we added.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
717 return ResultFromShort(idCmd-idCmdFirst);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
718 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
719
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
720 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
721 // FUNCTION: CShellExt::InvokeCommand(LPCMINVOKECOMMANDINFO)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
722 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
723 // PURPOSE: Called by the shell after the user has selected on of the
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
724 // menu items that was added in QueryContextMenu().
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
725 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
726 // PARAMETERS:
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
727 // lpcmi - Pointer to an CMINVOKECOMMANDINFO structure
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
728 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
729 // RETURN VALUE:
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
730 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
731 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
732 // COMMENTS:
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
733 //
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
734
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
735 STDMETHODIMP CShellExt::InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
736 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
737 HRESULT hr = E_INVALIDARG;
25413
ee2808fb1be9 patch 8.2.3243: MS-Windows: "edit with multiple Vim" choice is less useful
Bram Moolenaar <Bram@vim.org>
parents: 22924
diff changeset
738 int gvimExtraOptions;
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
739
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
740 // If HIWORD(lpcmi->lpVerb) then we have been called programmatically
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
741 // and lpVerb is a command that should be invoked. Otherwise, the shell
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
742 // has called us, and LOWORD(lpcmi->lpVerb) is the menu ID the user has
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
743 // selected. Actually, it's (menu ID - idCmdFirst) from QueryContextMenu().
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
744 if (!HIWORD(lpcmi->lpVerb))
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
745 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
746 UINT idCmd = LOWORD(lpcmi->lpVerb);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
747
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
748 if (idCmd >= m_edit_existing_off)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
749 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
750 // Existing with vim instance
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
751 hr = PushToWindow(lpcmi->hwnd,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
752 lpcmi->lpDirectory,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
753 lpcmi->lpVerb,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
754 lpcmi->lpParameters,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
755 lpcmi->nShow,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
756 idCmd - m_edit_existing_off);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
757 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
758 else
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
759 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
760 switch (idCmd)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
761 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
762 case 0:
25413
ee2808fb1be9 patch 8.2.3243: MS-Windows: "edit with multiple Vim" choice is less useful
Bram Moolenaar <Bram@vim.org>
parents: 22924
diff changeset
763 gvimExtraOptions = EDIT_WITH_VIM_USE_TABPAGES;
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
764 break;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
765 case 1:
25413
ee2808fb1be9 patch 8.2.3243: MS-Windows: "edit with multiple Vim" choice is less useful
Bram Moolenaar <Bram@vim.org>
parents: 22924
diff changeset
766 gvimExtraOptions = EDIT_WITH_VIM_NO_OPTIONS;
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
767 break;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
768 case 2:
25413
ee2808fb1be9 patch 8.2.3243: MS-Windows: "edit with multiple Vim" choice is less useful
Bram Moolenaar <Bram@vim.org>
parents: 22924
diff changeset
769 gvimExtraOptions = EDIT_WITH_VIM_IN_DIFF_MODE;
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
770 break;
25413
ee2808fb1be9 patch 8.2.3243: MS-Windows: "edit with multiple Vim" choice is less useful
Bram Moolenaar <Bram@vim.org>
parents: 22924
diff changeset
771 default:
ee2808fb1be9 patch 8.2.3243: MS-Windows: "edit with multiple Vim" choice is less useful
Bram Moolenaar <Bram@vim.org>
parents: 22924
diff changeset
772 // If execution reaches this point we likely have an
ee2808fb1be9 patch 8.2.3243: MS-Windows: "edit with multiple Vim" choice is less useful
Bram Moolenaar <Bram@vim.org>
parents: 22924
diff changeset
773 // inconsistency between the code that setup the menus
ee2808fb1be9 patch 8.2.3243: MS-Windows: "edit with multiple Vim" choice is less useful
Bram Moolenaar <Bram@vim.org>
parents: 22924
diff changeset
774 // and this code that determines what the user
ee2808fb1be9 patch 8.2.3243: MS-Windows: "edit with multiple Vim" choice is less useful
Bram Moolenaar <Bram@vim.org>
parents: 22924
diff changeset
775 // selected. This should be detected and fixed during
ee2808fb1be9 patch 8.2.3243: MS-Windows: "edit with multiple Vim" choice is less useful
Bram Moolenaar <Bram@vim.org>
parents: 22924
diff changeset
776 // development.
ee2808fb1be9 patch 8.2.3243: MS-Windows: "edit with multiple Vim" choice is less useful
Bram Moolenaar <Bram@vim.org>
parents: 22924
diff changeset
777 return E_FAIL;
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
778 }
26682
64dac9ff015e patch 8.2.3870: MS-Windows: wrong dir when using right-click context menu
Bram Moolenaar <Bram@vim.org>
parents: 25413
diff changeset
779
64dac9ff015e patch 8.2.3870: MS-Windows: wrong dir when using right-click context menu
Bram Moolenaar <Bram@vim.org>
parents: 25413
diff changeset
780 LPCMINVOKECOMMANDINFOEX lpcmiex = (LPCMINVOKECOMMANDINFOEX)lpcmi;
64dac9ff015e patch 8.2.3870: MS-Windows: wrong dir when using right-click context menu
Bram Moolenaar <Bram@vim.org>
parents: 25413
diff changeset
781 LPCWSTR currentDirectory = lpcmi->cbSize == sizeof(CMINVOKECOMMANDINFOEX) ? lpcmiex->lpDirectoryW : NULL;
64dac9ff015e patch 8.2.3870: MS-Windows: wrong dir when using right-click context menu
Bram Moolenaar <Bram@vim.org>
parents: 25413
diff changeset
782
25413
ee2808fb1be9 patch 8.2.3243: MS-Windows: "edit with multiple Vim" choice is less useful
Bram Moolenaar <Bram@vim.org>
parents: 22924
diff changeset
783 hr = InvokeSingleGvim(lpcmi->hwnd,
26682
64dac9ff015e patch 8.2.3870: MS-Windows: wrong dir when using right-click context menu
Bram Moolenaar <Bram@vim.org>
parents: 25413
diff changeset
784 currentDirectory,
25413
ee2808fb1be9 patch 8.2.3243: MS-Windows: "edit with multiple Vim" choice is less useful
Bram Moolenaar <Bram@vim.org>
parents: 22924
diff changeset
785 lpcmi->lpVerb,
ee2808fb1be9 patch 8.2.3243: MS-Windows: "edit with multiple Vim" choice is less useful
Bram Moolenaar <Bram@vim.org>
parents: 22924
diff changeset
786 lpcmi->lpParameters,
ee2808fb1be9 patch 8.2.3243: MS-Windows: "edit with multiple Vim" choice is less useful
Bram Moolenaar <Bram@vim.org>
parents: 22924
diff changeset
787 lpcmi->nShow,
ee2808fb1be9 patch 8.2.3243: MS-Windows: "edit with multiple Vim" choice is less useful
Bram Moolenaar <Bram@vim.org>
parents: 22924
diff changeset
788 gvimExtraOptions);
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
789 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
790 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
791 return hr;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
792 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
793
1686
c7c53db66b55 updated for version 7.2b-019
vimboss
parents: 1366
diff changeset
794 STDMETHODIMP CShellExt::PushToWindow(HWND /* hParent */,
c7c53db66b55 updated for version 7.2b-019
vimboss
parents: 1366
diff changeset
795 LPCSTR /* pszWorkingDir */,
c7c53db66b55 updated for version 7.2b-019
vimboss
parents: 1366
diff changeset
796 LPCSTR /* pszCmd */,
c7c53db66b55 updated for version 7.2b-019
vimboss
parents: 1366
diff changeset
797 LPCSTR /* pszParam */,
c7c53db66b55 updated for version 7.2b-019
vimboss
parents: 1366
diff changeset
798 int /* iShowCmd */,
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
799 int idHWnd)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
800 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
801 HWND hWnd = m_hWnd[idHWnd];
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
802
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
803 // Show and bring vim instance to foreground
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
804 if (IsIconic(hWnd) != 0)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
805 ShowWindow(hWnd, SW_RESTORE);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
806 else
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
807 ShowWindow(hWnd, SW_SHOW);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
808 SetForegroundWindow(hWnd);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
809
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
810 // Post the selected files to the vim instance
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
811 PostMessage(hWnd, WM_DROPFILES, (WPARAM)medium.hGlobal, 0);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
812
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
813 return NOERROR;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
814 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
815
1686
c7c53db66b55 updated for version 7.2b-019
vimboss
parents: 1366
diff changeset
816 STDMETHODIMP CShellExt::GetCommandString(UINT_PTR /* idCmd */,
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
817 UINT uFlags,
1686
c7c53db66b55 updated for version 7.2b-019
vimboss
parents: 1366
diff changeset
818 UINT FAR * /* reserved */,
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
819 LPSTR pszName,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
820 UINT cchMax)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
821 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
822 if (uFlags == GCS_HELPTEXT && cchMax > 35)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
823 lstrcpy(pszName, _("Edits the selected file(s) with Vim"));
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
824
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
825 return NOERROR;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
826 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
827
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
828 BOOL CALLBACK CShellExt::EnumWindowsProc(HWND hWnd, LPARAM lParam)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
829 {
415
165c628aa9fc updated for version 7.0108
vimboss
parents: 26
diff changeset
830 char temp[BUFSIZE];
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
831
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
832 // First do a bunch of check
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
833 // No invisible window
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
834 if (!IsWindowVisible(hWnd)) return TRUE;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
835 // No child window ???
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
836 // if (GetParent(hWnd)) return TRUE;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
837 // Class name should be Vim, if failed to get class name, return
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
838 if (GetClassName(hWnd, temp, sizeof(temp)) == 0)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
839 return TRUE;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
840 // Compare class name to that of vim, if not, return
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
841 if (_strnicmp(temp, "vim", sizeof("vim")) != 0)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
842 return TRUE;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
843 // First check if the number of vim instance exceeds MAX_HWND
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
844 CShellExt *cs = (CShellExt*) lParam;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
845 if (cs->m_cntOfHWnd >= MAX_HWND) return TRUE;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
846 // Now we get the vim window, put it into some kind of array
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
847 cs->m_hWnd[cs->m_cntOfHWnd] = hWnd;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
848 cs->m_cntOfHWnd ++;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
849
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
850 return TRUE; // continue enumeration (otherwise this would be false)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
851 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
852
6805
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
853 BOOL CShellExt::LoadMenuIcon()
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
854 {
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
855 char vimExeFile[BUFSIZE];
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
856 getGvimName(vimExeFile, 1);
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
857 if (vimExeFile[0] == '\0')
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
858 return FALSE;
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
859 HICON hVimIcon;
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
860 if (ExtractIconEx(vimExeFile, 0, NULL, &hVimIcon, 1) == 0)
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
861 return FALSE;
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
862 m_hVimIconBitmap = IconToBitmap(hVimIcon,
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
863 GetSysColorBrush(COLOR_MENU),
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
864 GetSystemMetrics(SM_CXSMICON),
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
865 GetSystemMetrics(SM_CYSMICON));
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
866 return TRUE;
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
867 }
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
868
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
869 static char *
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
870 searchpath(char *name)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
871 {
415
165c628aa9fc updated for version 7.0108
vimboss
parents: 26
diff changeset
872 static char widename[2 * BUFSIZE];
165c628aa9fc updated for version 7.0108
vimboss
parents: 26
diff changeset
873 static char location[2 * BUFSIZE + 2];
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
874
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
875 // There appears to be a bug in FindExecutableA() on Windows NT.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
876 // Use FindExecutableW() instead...
12626
aca41efd888c patch 8.0.1191: MS-Windows: missing 32 and 64 bit files in installer
Christian Brabandt <cb@256bit.org>
parents: 8180
diff changeset
877 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)name, -1,
aca41efd888c patch 8.0.1191: MS-Windows: missing 32 and 64 bit files in installer
Christian Brabandt <cb@256bit.org>
parents: 8180
diff changeset
878 (LPWSTR)widename, BUFSIZE);
aca41efd888c patch 8.0.1191: MS-Windows: missing 32 and 64 bit files in installer
Christian Brabandt <cb@256bit.org>
parents: 8180
diff changeset
879 if (FindExecutableW((LPCWSTR)widename, (LPCWSTR)"",
aca41efd888c patch 8.0.1191: MS-Windows: missing 32 and 64 bit files in installer
Christian Brabandt <cb@256bit.org>
parents: 8180
diff changeset
880 (LPWSTR)location) > (HINSTANCE)32)
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
881 {
12626
aca41efd888c patch 8.0.1191: MS-Windows: missing 32 and 64 bit files in installer
Christian Brabandt <cb@256bit.org>
parents: 8180
diff changeset
882 WideCharToMultiByte(CP_ACP, 0, (LPWSTR)location, -1,
aca41efd888c patch 8.0.1191: MS-Windows: missing 32 and 64 bit files in installer
Christian Brabandt <cb@256bit.org>
parents: 8180
diff changeset
883 (LPSTR)widename, 2 * BUFSIZE, NULL, NULL);
aca41efd888c patch 8.0.1191: MS-Windows: missing 32 and 64 bit files in installer
Christian Brabandt <cb@256bit.org>
parents: 8180
diff changeset
884 return widename;
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
885 }
1366
7e7da11555d2 updated for version 7.1-080
vimboss
parents: 1226
diff changeset
886 return (char *)"";
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
887 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
888
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
889
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
890 STDMETHODIMP CShellExt::InvokeSingleGvim(HWND hParent,
26682
64dac9ff015e patch 8.2.3870: MS-Windows: wrong dir when using right-click context menu
Bram Moolenaar <Bram@vim.org>
parents: 25413
diff changeset
891 LPCWSTR workingDir,
1686
c7c53db66b55 updated for version 7.2b-019
vimboss
parents: 1366
diff changeset
892 LPCSTR /* pszCmd */,
c7c53db66b55 updated for version 7.2b-019
vimboss
parents: 1366
diff changeset
893 LPCSTR /* pszParam */,
c7c53db66b55 updated for version 7.2b-019
vimboss
parents: 1366
diff changeset
894 int /* iShowCmd */,
25413
ee2808fb1be9 patch 8.2.3243: MS-Windows: "edit with multiple Vim" choice is less useful
Bram Moolenaar <Bram@vim.org>
parents: 22924
diff changeset
895 int gvimExtraOptions)
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
896 {
2295
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
897 wchar_t m_szFileUserClickedOn[BUFSIZE];
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
898 wchar_t *cmdStrW;
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
899 size_t cmdlen;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
900 size_t len;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
901 UINT i;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
902
415
165c628aa9fc updated for version 7.0108
vimboss
parents: 26
diff changeset
903 cmdlen = BUFSIZE;
2295
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
904 cmdStrW = (wchar_t *) malloc(cmdlen * sizeof(wchar_t));
15154
eb0d8065d3f8 patch 8.1.0587: GvimExt: realloc() failing is not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 14962
diff changeset
905 if (cmdStrW == NULL)
15158
a9340baa872f patch 8.1.0589: compilation error in gvimext.cpp
Bram Moolenaar <Bram@vim.org>
parents: 15154
diff changeset
906 return E_FAIL;
6805
81cb471657e0 patch 7.4.724
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
907 getGvimInvocationW(cmdStrW);
2295
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
908
25413
ee2808fb1be9 patch 8.2.3243: MS-Windows: "edit with multiple Vim" choice is less useful
Bram Moolenaar <Bram@vim.org>
parents: 22924
diff changeset
909 if (gvimExtraOptions == EDIT_WITH_VIM_IN_DIFF_MODE)
2295
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
910 wcscat(cmdStrW, L" -d");
25413
ee2808fb1be9 patch 8.2.3243: MS-Windows: "edit with multiple Vim" choice is less useful
Bram Moolenaar <Bram@vim.org>
parents: 22924
diff changeset
911 else if (gvimExtraOptions == EDIT_WITH_VIM_USE_TABPAGES)
ee2808fb1be9 patch 8.2.3243: MS-Windows: "edit with multiple Vim" choice is less useful
Bram Moolenaar <Bram@vim.org>
parents: 22924
diff changeset
912 wcscat(cmdStrW, L" -p");
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
913 for (i = 0; i < cbFiles; i++)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
914 {
2295
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
915 DragQueryFileW((HDROP)medium.hGlobal,
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
916 i,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
917 m_szFileUserClickedOn,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
918 sizeof(m_szFileUserClickedOn));
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
919
2295
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
920 len = wcslen(cmdStrW) + wcslen(m_szFileUserClickedOn) + 4;
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
921 if (len > cmdlen)
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
922 {
415
165c628aa9fc updated for version 7.0108
vimboss
parents: 26
diff changeset
923 cmdlen = len + BUFSIZE;
15154
eb0d8065d3f8 patch 8.1.0587: GvimExt: realloc() failing is not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 14962
diff changeset
924 wchar_t *cmdStrW_new = (wchar_t *)realloc(cmdStrW, cmdlen * sizeof(wchar_t));
eb0d8065d3f8 patch 8.1.0587: GvimExt: realloc() failing is not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 14962
diff changeset
925 if (cmdStrW_new == NULL)
15158
a9340baa872f patch 8.1.0589: compilation error in gvimext.cpp
Bram Moolenaar <Bram@vim.org>
parents: 15154
diff changeset
926 {
a9340baa872f patch 8.1.0589: compilation error in gvimext.cpp
Bram Moolenaar <Bram@vim.org>
parents: 15154
diff changeset
927 free(cmdStrW);
a9340baa872f patch 8.1.0589: compilation error in gvimext.cpp
Bram Moolenaar <Bram@vim.org>
parents: 15154
diff changeset
928 return E_FAIL;
a9340baa872f patch 8.1.0589: compilation error in gvimext.cpp
Bram Moolenaar <Bram@vim.org>
parents: 15154
diff changeset
929 }
15154
eb0d8065d3f8 patch 8.1.0587: GvimExt: realloc() failing is not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 14962
diff changeset
930 cmdStrW = cmdStrW_new;
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
931 }
2295
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
932 wcscat(cmdStrW, L" \"");
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
933 wcscat(cmdStrW, m_szFileUserClickedOn);
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
934 wcscat(cmdStrW, L"\"");
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
935 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
936
2295
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
937 STARTUPINFOW si;
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
938 PROCESS_INFORMATION pi;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
939
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
940 ZeroMemory(&si, sizeof(si));
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
941 si.cb = sizeof(si);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
942
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
943 // Start the child process.
2295
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
944 if (!CreateProcessW(NULL, // No module name (use command line).
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
945 cmdStrW, // Command line.
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
946 NULL, // Process handle not inheritable.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
947 NULL, // Thread handle not inheritable.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
948 FALSE, // Set handle inheritance to FALSE.
22924
db65bb242582 patch 8.2.2009: MS-Windows: setting $LANG in gvimext only causes problems
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
949 0, // No creation flags.
db65bb242582 patch 8.2.2009: MS-Windows: setting $LANG in gvimext only causes problems
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
950 NULL, // Use parent's environment block.
26682
64dac9ff015e patch 8.2.3870: MS-Windows: wrong dir when using right-click context menu
Bram Moolenaar <Bram@vim.org>
parents: 25413
diff changeset
951 workingDir, // Use parent's starting directory.
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
952 &si, // Pointer to STARTUPINFO structure.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
953 &pi) // Pointer to PROCESS_INFORMATION structure.
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
954 )
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
955 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
956 MessageBox(
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
957 hParent,
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
958 _("Error creating process: Check if gvim is in your path!"),
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
959 _("gvimext.dll error"),
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
960 MB_OK);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
961 }
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
962 else
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
963 {
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
964 CloseHandle(pi.hProcess);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
965 CloseHandle(pi.hThread);
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
966 }
2295
b9bc9c5df131 Support wide file names in gvimext. (Szabolcs Horvat)
Bram Moolenaar <bram@vim.org>
parents: 1953
diff changeset
967 free(cmdStrW);
10
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
968
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
969 return NOERROR;
4e2284e71352 updated for version 7.0002
vimboss
parents:
diff changeset
970 }