openMSX
win32-arggen.cc
Go to the documentation of this file.
1#ifdef _WIN32
2
3#include "win32-arggen.hh"
4#include "MSXException.hh"
5#include "utf8_checked.hh"
6#include "xrange.hh"
7#include <windows.h>
8#include <shellapi.h>
9
10namespace openmsx {
11
12ArgumentGenerator::~ArgumentGenerator()
13{
14 for (auto i : xrange(argc)) {
15 free(argv[i]);
16 }
17}
18
19char** ArgumentGenerator::GetArguments(int& argc_)
20{
21 if (argv.empty()) {
22 LPWSTR* pszArgList = CommandLineToArgvW(GetCommandLineW(), &argc);
23 if (!pszArgList) {
24 throw MSXException("Failed to obtain command line arguments");
25 }
26
27 argv.resize(argc);
28 for (auto i : xrange(argc)) {
29 argv[i] = strdup(utf8::utf16to8(pszArgList[i]).c_str());
30 }
31 LocalFree(pszArgList);
32 }
33
34 argc_ = argc;
35 return argv.data();
36}
37
38} // namespace openmsx
39
40#endif
This file implemented 3 utility functions:
Definition Autofire.cc:9
octet_iterator utf16to8(u16bit_iterator start, u16bit_iterator end, octet_iterator result)
constexpr auto xrange(T e)
Definition xrange.hh:132