-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnoconsole.c
More file actions
50 lines (41 loc) · 1.11 KB
/
noconsole.c
File metadata and controls
50 lines (41 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <windows.h>
#include <shellapi.h>
#include <stdio.h>
#ifdef UNICODE
#define MAIN wWinMain
#else
#define MAIN WinMain
#endif
int WINAPI MAIN(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR pCmdLine, int nCmdShow)
{
int argnum = 1;
STARTUPINFO si;
PROCESS_INFORMATION pi;
DWORD exit_code;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
ZeroMemory(&pi, sizeof(pi));
/* Note: argnum is not like argc... */
if (argnum < 1) {
fputs("Usage: noconsole <program> [<args>...]\n", stderr);
ExitProcess(1);
}
/* Start the child process */
if (!CreateProcess(NULL, pCmdLine, NULL, NULL, FALSE, 0, NULL, NULL, /* Note that the previous should maybe be set to the cwd of the program being run */
&si,
&pi))
{
fprintf(stderr, "Error starting process, code %d.\n", GetLastError());
ExitProcess(1);
}
/* Wait for child exit */
WaitForSingleObject(pi.hProcess, INFINITE);
GetExitCodeProcess(pi.hProcess, &exit_code);
/* Clean up the handles */
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
ExitProcess(exit_code);
return 0;
}