OXYGENHUB
◆ main openmsx / src / utils / win32-arggen.cc
664 B · C++ · last changed chore(): initial commit 1 month ago source blame history raw
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
10
namespace openmsx {
11
12
ArgumentGenerator::ArgumentGenerator()
13
{
14
	int argc = 0;
15
	LPWSTR* pszArgList = CommandLineToArgvW(GetCommandLineW(), &argc);
16
	if (!pszArgList) {
17
		throw MSXException("Failed to obtain command line arguments");
18
	}
19
20
	args = dynarray<char*>(argc);
21
	for (auto i : xrange(argc)) {
22
		args[i] = strdup(utf8::utf16to8(pszArgList[i]).c_str());
23
	}
24
	LocalFree(pszArgList);
25
}
26
27
ArgumentGenerator::~ArgumentGenerator()
28
{
29
	for (auto* arg : args) {
30
		free(arg);
31
	}
32
}
33
34
} // namespace openmsx
35
36
#endif