-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnodebug.max.cpp
More file actions
68 lines (57 loc) · 1.75 KB
/
nodebug.max.cpp
File metadata and controls
68 lines (57 loc) · 1.75 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <iostream>
#include <windows.h>
#include <string>
#include <shlwapi.h>
#pragma comment(lib, "shlwapi.lib")
int main(int argc, char* argv[]) {
// Get the name of the current exe file
char exePath[MAX_PATH];
GetModuleFileNameA(NULL, exePath, MAX_PATH);
std::string exePathStr(exePath); // Convert char array to std::string
// Replace ".max.exe" with ".exe" in the executable path
size_t maxPos = exePathStr.find(".max.exe");
if (maxPos != std::string::npos) {
exePathStr.replace(maxPos, 8, ".exe");
} else {
std::cerr << "Unknown exe name: " << exePathStr << std::endl;
return 1;
}
// Check if the target exe file exists
if (!PathFileExistsA(exePathStr.c_str())) {
std::cerr << "Cannot find " << exePathStr << " in the same directory." << std::endl;
return 1;
}
// Create the argument string for the target exe file
std::string arguments;
for (int i = 1; i < argc; ++i) {
arguments += argv[i];
if (i < argc - 1) {
arguments += " ";
}
}
// Start the target exe file in a maximized window with the arguments
STARTUPINFO si = { sizeof(si) };
PROCESS_INFORMATION pi;
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_MAXIMIZE;
if (!CreateProcessA(
exePathStr.c_str(),
const_cast<char*>(arguments.c_str()),
NULL,
NULL,
FALSE,
0,
NULL,
NULL,
&si,
&pi)) {
std::cerr << "Could not start " << exePathStr << std::endl;
return 1;
}
// Wait for the process to finish
WaitForSingleObject(pi.hProcess, INFINITE);
// Close the handles
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return 0;
}