Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ShellExecute to run emulators on Win32 #701

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions es-core/src/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

#include <SDL_events.h>
#ifdef WIN32
#include <codecvt>
#include <windows.h>
#include "Shlwapi.h"
#pragma comment(lib, "Shlwapi.lib")
#else
#include <unistd.h>
#endif
Expand Down Expand Up @@ -31,12 +33,24 @@ int runRestartCommand()
int runSystemCommand(const std::string& cmd_utf8)
{
#ifdef WIN32
// on Windows we use _wsystem to support non-ASCII paths
// which requires converting from utf8 to a wstring
typedef std::codecvt_utf8<wchar_t> convert_type;
std::wstring_convert<convert_type, wchar_t> converter;
std::wstring wchar_str = converter.from_bytes(cmd_utf8);
return _wsystem(wchar_str.c_str());
std::string args = std::string(PathGetArgs(cmd_utf8.c_str()));
std::string program = cmd_utf8.substr(0, cmd_utf8.length() - args.length());
SHELLEXECUTEINFO ShExecInfo = {0};
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = program.c_str();
ShExecInfo.lpParameters = args.c_str();
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_SHOW;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
WaitForSingleObject(ShExecInfo.hProcess, INFINITE);
CloseHandle(ShExecInfo.hProcess);
DWORD dwExitCode = 0;
GetExitCodeProcess(ShExecInfo.hProcess, &dwExitCode);
return dwExitCode;
#else
return system(cmd_utf8.c_str());
#endif
Expand Down