forked from ethereum/aleth
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWinMain.cpp
More file actions
72 lines (63 loc) · 1.21 KB
/
WinMain.cpp
File metadata and controls
72 lines (63 loc) · 1.21 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// http://www.flipcode.com/archives/WinMain_Command_Line_Parser.shtml
// COTD Entry submitted by Max McGuire [amcguire@andrew.cmu.edu]
#include <windows.h>
extern int main(int argc, char* argv[]);
int WINAPI WinMain(HINSTANCE /*instance*/, HINSTANCE /*prev_instance*/, char* command_line, int /*show_command*/)
{
int argc;
char** argv;
char* arg;
int index;
int result;
// count the arguments
argc = 1;
arg = command_line;
while (arg[0] != 0)
{
while (arg[0] != 0 && arg[0] == ' ')
{
arg++;
}
if (arg[0] != 0)
{
argc++;
while (arg[0] != 0 && arg[0] != ' ')
{
arg++;
}
}
}
// tokenize the arguments
argv = (char**)malloc(argc * sizeof(char*));
arg = command_line;
index = 1;
while (arg[0] != 0)
{
while (arg[0] != 0 && arg[0] == ' ')
{
arg++;
}
if (arg[0] != 0)
{
argv[index] = arg;
index++;
while (arg[0] != 0 && arg[0] != ' ')
{
arg++;
}
if (arg[0] != 0)
{
arg[0] = 0;
arg++;
}
}
}
// put the program name into argv[0]
char filename[_MAX_PATH];
GetModuleFileName(NULL, filename, _MAX_PATH);
argv[0] = filename;
// call the user specified main function
result = main(argc, argv);
free(argv);
return result;
}