Loading...
Searching...
No Matches
WinMainToMain.hpp
1#pragma once
2
3#if defined(_MSC_VER)
4#include <ShlObj.h>
5#include <shellapi.h>
6#include <stdio.h>
7#include <windows.h>
8static inline char* wideToMulti(int codePage, const wchar_t* aw)
9{
10 const int required = WideCharToMultiByte(codePage, 0, aw, -1, NULL, 0, NULL, NULL);
11 char* result = new char[required];
12 WideCharToMultiByte(codePage, 0, aw, -1, result, required, NULL, NULL);
13 return result;
14}
15
16extern "C" int APIENTRY
17WinMain(HINSTANCE, HINSTANCE, LPSTR /*cmdParamarg*/, int /* cmdShow */)
18{
19 int argc;
20 wchar_t** argvW = CommandLineToArgvW(GetCommandLineW(), &argc);
21 if(!argvW)
22 return -1;
23 char** argv = new char*[argc + 1];
24 for(int i = 0; i < argc; ++i)
25 argv[i] = wideToMulti(CP_ACP, argvW[i]);
26 argv[argc] = nullptr;
27 LocalFree(argvW);
28 const int exitCode = main(argc, argv);
29 for(int i = 0; i < argc && argv[i]; ++i)
30 delete[] argv[i];
31 delete[] argv;
32 return exitCode;
33}
34#endif