-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwmain.c
43 lines (33 loc) · 1.14 KB
/
wmain.c
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
#include <windows.h>
// https://docs.microsoft.com/en-us/cpp/build/reference/entry-entry-point-symbol
#pragma comment(linker, "/ENTRY:wWinMainCRTStartup")
extern int __cdecl main();
int wmain(int argc, wchar_t* argv[])
{
char** args;
int nbytes = sizeof(char*) * (argc + 1);
HANDLE heap = GetProcessHeap();
for (int i = 0; i < argc; ++i)
nbytes += WideCharToMultiByte(CP_UTF8, 0, argv[i], -1, NULL, 0, NULL, NULL);
args = HeapAlloc(heap, 0, nbytes);
args[0] = (char*)(args + argc + 1);
for (int i = 0; i < argc; ++i)
args[i+1] = args[i] + WideCharToMultiByte(CP_UTF8, 0, argv[i], -1, args[i], nbytes, NULL, NULL);
args[argc] = NULL;
argc = main(argc, args);
HeapFree(heap, 0, args);
return argc;
}
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
{
(void) hInstance;
(void) hPrevInstance;
(void) lpCmdLine;
(void) nCmdShow;
int argc;
wchar_t** argv;
argv = CommandLineToArgvW(GetCommandLineW(), &argc);
argc = wmain(argc, argv);
LocalFree(argv);
return argc;
}