-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWinion_WindowsTerminal.cpp
More file actions
51 lines (42 loc) · 1.48 KB
/
Copy pathWinion_WindowsTerminal.cpp
File metadata and controls
51 lines (42 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <windows.h>
#include <string>
#include <vector>
std::string GetExecutableDir() {
char exePath[MAX_PATH] = {0};
GetModuleFileNameA(NULL, exePath, MAX_PATH);
std::string path(exePath);
size_t pos = path.find_last_of("\\/");
return (pos != std::string::npos) ? path.substr(0, pos) : path;
}
std::vector<char> MakeCommandLine(const std::string& command) {
std::vector<char> buffer(command.begin(), command.end());
buffer.push_back('\0');
return buffer;
}
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR lpCmdLine, int) {
const std::string dirPath = GetExecutableDir();
const std::string wtPath = dirPath + "\\Bin\\WindowsTerminal\\WindowsTerminal.exe";
const std::string winionPath = dirPath + "\\Winion.exe";
std::string cmdLine = "\"" + wtPath + "\" \"" + winionPath + "\"";
if (lpCmdLine && *lpCmdLine) {
cmdLine += " ";
cmdLine += lpCmdLine;
}
std::vector<char> cmdBuffer = MakeCommandLine(cmdLine);
STARTUPINFOA si{ sizeof(si) };
PROCESS_INFORMATION pi{};
if (!CreateProcessA(
NULL,
cmdBuffer.data(),
NULL, NULL, FALSE, 0,
NULL,
dirPath.c_str(),
&si, &pi))
{
MessageBoxA(NULL, "Impossible de lancer WindowsTerminal.exe", "Erreur", MB_OK | MB_ICONERROR);
return 1;
}
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return 0;
}