1 | /* editwrap.c |
---|
2 | * Run svxedit.tcl from the same directory as this program |
---|
3 | * Copyright (C) 2002,2010 Olly Betts |
---|
4 | * |
---|
5 | * This program is free software; you can redistribute it and/or modify |
---|
6 | * it under the terms of the GNU General Public License as published by |
---|
7 | * the Free Software Foundation; either version 2 of the License, or |
---|
8 | * (at your option) any later version. |
---|
9 | * |
---|
10 | * This program is distributed in the hope that it will be useful, |
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
13 | * GNU General Public License for more details. |
---|
14 | * |
---|
15 | * You should have received a copy of the GNU General Public License |
---|
16 | * along with this program; if not, write to the Free Software |
---|
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
18 | */ |
---|
19 | |
---|
20 | #ifdef HAVE_CONFIG_H |
---|
21 | #include <config.h> |
---|
22 | #endif |
---|
23 | |
---|
24 | #include <stdlib.h> |
---|
25 | #include <string.h> |
---|
26 | #include <windows.h> |
---|
27 | |
---|
28 | int APIENTRY |
---|
29 | WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow) |
---|
30 | { |
---|
31 | DWORD len = 256; |
---|
32 | wchar_t *buf = NULL, *p; |
---|
33 | PWSTR cmd_line; |
---|
34 | hInst = hInst; /* suppress compiler warning */ |
---|
35 | hPrevInst = hPrevInst; /* suppress compiler warning */ |
---|
36 | lpCmdLine = lpCmdLine; /* suppress compiler warning */ |
---|
37 | while (1) { |
---|
38 | DWORD got; |
---|
39 | buf = realloc(buf, len * 2); |
---|
40 | if (!buf) exit(1); |
---|
41 | got = GetModuleFileNameW(NULL, buf, len); |
---|
42 | if (got + 12 < len) break; |
---|
43 | len += len; |
---|
44 | } |
---|
45 | /* Strange Win32 nastiness - strip prefix "\\?\" if present */ |
---|
46 | if (wcsncmp(buf, L"\\\\?\\", 4) == 0) buf += 4; |
---|
47 | p = wcsrchr(buf, L'\\'); |
---|
48 | if (p) ++p; else p = buf; |
---|
49 | wcscpy(p, L"svxedit.tcl"); |
---|
50 | cmd_line = GetCommandLineW(); |
---|
51 | /* ShellExecute returns an HINSTANCE for some wacko reason - the docs say |
---|
52 | * the only valid operation is to convert it to an int. Marvellous. */ |
---|
53 | if ((int)ShellExecuteW(NULL, NULL, buf, cmd_line, NULL, nCmdShow) <= 32) { |
---|
54 | ShellExecuteW(NULL, NULL, L"notepad", cmd_line, NULL, nCmdShow); |
---|
55 | } |
---|
56 | return 0; |
---|
57 | } |
---|