[project @ 2001-06-07 11:07:51 by sewardj]
[ghc-hetmet.git] / ghc / InstallShield / runexe.c
1 #include <stdarg.h>
2 #include <stdio.h>
3 #include <windows.h>
4
5 const char *prog = "runexe";
6
7 #define BUFLEN 1025
8
9 void die(char *fmt, ...)
10 {
11   va_list ap = va_start(ap, fmt);
12
13   fprintf(stderr, "%s: ", prog);
14   vfprintf(stderr, fmt, ap);
15   fprintf(stderr, "\n");
16   va_end(ap);
17   exit(1);
18 }
19
20 void warn(char *fmt, ...)
21 {
22   va_list ap = va_start(ap, fmt);
23
24   fprintf(stderr, "%s: ", prog);
25   vfprintf(stderr, fmt, ap);
26   fprintf(stderr, "\n");
27   va_end(ap);
28 }
29   
30 int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdParam, int nCmdShow)
31 {
32   STARTUPINFO sInfo;
33   PROCESS_INFORMATION pInfo;
34   TCHAR buf[BUFLEN];
35
36   sInfo.cb              = sizeof(STARTUPINFO);
37   sInfo.lpReserved      = NULL;
38   sInfo.lpReserved2     = NULL;
39   sInfo.cbReserved2     = 0;
40   sInfo.lpDesktop       = NULL;
41   sInfo.lpTitle         = NULL;
42   sInfo.dwFlags         = 0;
43
44   if (GetCurrentDirectory(BUFLEN, buf) == 0) die("no parameters given");
45   if (strlen(lpszCmdParam) == 0) warn("couldn't get current directory");
46   warn("cwd: %s\n", buf);
47   warn("runexing >>>%s<<<\n", lpszCmdParam);
48   CreateProcess(NULL, lpszCmdParam, NULL, NULL, FALSE, 0, NULL, NULL, &sInfo, &pInfo);
49   return 0;
50 }