Skip to content

Commit

Permalink
Win32 API updates and code optimization
Browse files Browse the repository at this point in the history
Signed-off-by: Fxzx mic <[email protected]>
  • Loading branch information
fxzxmic committed Mar 31, 2024
1 parent d8d92a3 commit 7e28ed7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 34 deletions.
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
.vs
x64
x86
.vscode
build
*.h
*.rc
*.aps
*.sln
*.vcxproj
*.vcxproj.*
*.vcxproj.*
*.obj
55 changes: 24 additions & 31 deletions CMD_to_Bash.cpp
Original file line number Diff line number Diff line change
@@ -1,40 +1,33 @@
#include <iostream>
#include <Windows.h>
#include <Windows.h>
#include <iostream>

using namespace std;

int main(int argc, char* argv[]) {
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char fname[_MAX_FNAME];
char ext[_MAX_EXT];
_splitpath_s(argv[0], drive, sizeof(drive), dir, sizeof(dir), fname, sizeof(fname), ext, sizeof(ext));
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char fname[_MAX_FNAME];
char ext[_MAX_EXT];
_splitpath_s(argv[0], drive, _countof(drive), dir, _countof(dir), fname, _countof(fname), ext, _countof(ext));

string ch = "bash.exe -c \"\\\"\"";
ch += fname;
int count = 1;
for (count; count < argc; ++count) {
ch += " ";
ch += argv[count];
}
ch += "\\\"\"\"";
string ch = "bash.exe -c \"\\\"\"";
ch += fname;
for (int i = 1; i < argc; ++i) {
ch += " ";
ch += argv[i];
}
ch += "\\\"\"\"";

DWORD dwExitCode;
wstring widstr;
widstr = wstring(ch.begin(), ch.end());
LPWSTR sConLin = (LPWSTR)widstr.c_str();
DWORD dwExitCode;
STARTUPINFO si = { sizeof(si) };
PROCESS_INFORMATION pi;

STARTUPINFO si;
PROCESS_INFORMATION pi;
memset(&si, 0, sizeof(si));
memset(&pi, 0, sizeof(pi));
CreateProcess(NULL, (LPSTR)ch.c_str(), NULL, NULL, true, 0, NULL, NULL, &si, &pi);

CreateProcess(NULL, sConLin, NULL, NULL, true, 0, NULL, NULL, &si, &pi);

CloseHandle(pi.hThread);
WaitForSingleObject(pi.hProcess, INFINITE);
GetExitCodeProcess(pi.hProcess, &dwExitCode);
CloseHandle(pi.hProcess);

return dwExitCode;
CloseHandle(pi.hThread);
WaitForSingleObject(pi.hProcess, INFINITE);
GetExitCodeProcess(pi.hProcess, &dwExitCode);
CloseHandle(pi.hProcess);

return dwExitCode;
}

0 comments on commit 7e28ed7

Please sign in to comment.