Windows: use wide char interfaces
Exchange file names and command line parameters with the system using wchar_t interfaces: allows preserving values which can be reversibly transcoded in the current multibyte charset (which can't be UTF-8). Store all file paths internally in UTF-8
This commit is contained in:
@@ -32,6 +32,7 @@
|
||||
#include <psapi.h>
|
||||
#include "smallut.h"
|
||||
#include "pathut.h"
|
||||
#include "transcode.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -752,7 +753,7 @@ int ExecCmd::startExec(const string &cmd, const vector<string>& args,
|
||||
return false;
|
||||
}
|
||||
|
||||
STARTUPINFO siStartInfo;
|
||||
STARTUPINFOW siStartInfo;
|
||||
BOOL bSuccess = FALSE;
|
||||
|
||||
// Set up members of the PROCESS_INFORMATION structure.
|
||||
@@ -760,8 +761,8 @@ int ExecCmd::startExec(const string &cmd, const vector<string>& args,
|
||||
|
||||
// Set up members of the STARTUPINFO structure.
|
||||
// This structure specifies the STDIN and STDOUT handles for redirection.
|
||||
ZeroMemory(&siStartInfo, sizeof(STARTUPINFO));
|
||||
siStartInfo.cb = sizeof(STARTUPINFO);
|
||||
ZeroMemory(&siStartInfo, sizeof(siStartInfo));
|
||||
siStartInfo.cb = sizeof(siStartInfo);
|
||||
if (m->m_flags & EXF_SHOWWINDOW) {
|
||||
siStartInfo.dwFlags |= STARTF_USESTDHANDLES;
|
||||
if (m->m_flags & EXF_MAXIMIZED) {
|
||||
@@ -782,12 +783,15 @@ int ExecCmd::startExec(const string &cmd, const vector<string>& args,
|
||||
|
||||
// Create the child process.
|
||||
// Need a writable buffer for the command line, for some reason.
|
||||
LOGDEB1("ExecCmd:startExec: cmdline [" << (cmdline) << "]\n" );
|
||||
LOGDEB("ExecCmd:startExec: cmdline [" << cmdline << "]\n");
|
||||
#if 0
|
||||
LPSTR buf = (LPSTR)malloc(cmdline.size() + 1);
|
||||
memcpy(buf, cmdline.c_str(), cmdline.size());
|
||||
buf[cmdline.size()] = 0;
|
||||
bSuccess = CreateProcess(NULL,
|
||||
buf, // command line
|
||||
#endif
|
||||
SYSPATH(cmdline, wcmdline);
|
||||
bSuccess = CreateProcessW(NULL,
|
||||
wcmdline, // command line
|
||||
NULL, // process security attributes
|
||||
NULL, // primary thread security attrs
|
||||
TRUE, // handles are inherited
|
||||
@@ -798,9 +802,10 @@ int ExecCmd::startExec(const string &cmd, const vector<string>& args,
|
||||
&m->m_piProcInfo); // PROCESS_INFORMATION
|
||||
if (!bSuccess) {
|
||||
printError("ExecCmd::doexec: CreateProcess");
|
||||
}
|
||||
}
|
||||
|
||||
free(envir);
|
||||
free(buf);
|
||||
// free(buf);
|
||||
// Close child-side handles else we'll never see eofs
|
||||
if (!CloseHandle(hOutputWrite))
|
||||
printError("CloseHandle");
|
||||
|
||||
@@ -19,6 +19,9 @@
|
||||
#include <shellapi.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "safewindows.h"
|
||||
#include "pathut.h"
|
||||
#include "transcode.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -41,6 +44,10 @@ int op_flags;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int wargc;
|
||||
wchar_t **wargv = CommandLineToArgvW(GetCommandLineW(), &wargc);
|
||||
|
||||
// Yes we could use wargv
|
||||
thisprog = argv[0];
|
||||
argc--; argv++;
|
||||
int imode = 0;
|
||||
@@ -62,7 +69,9 @@ int main(int argc, char *argv[])
|
||||
if (argc != 1) {
|
||||
Usage();
|
||||
}
|
||||
char *fn = strdup(argv[0]);
|
||||
|
||||
wchar_t *wfn = wargv[1];
|
||||
|
||||
// Do we need this ?
|
||||
//https://msdn.microsoft.com/en-us/library/windows/desktop/bb762153%28v=vs.85%29.aspx
|
||||
//CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
|
||||
@@ -73,9 +82,10 @@ int main(int argc, char *argv[])
|
||||
default: wmode = SW_SHOWNORMAL; break;
|
||||
}
|
||||
|
||||
int ret = (int)ShellExecute(NULL, "open", fn, NULL, NULL, wmode);
|
||||
int ret = (int)ShellExecuteW(NULL, L"open", wfn, NULL, NULL, wmode);
|
||||
if (ret) {
|
||||
fprintf(stderr, "ShellExecute returned %d\n", ret);
|
||||
}
|
||||
LocalFree(wargv);
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user