I am developing a code which will execute another exe by using win32 api function CreateProcess.
#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
STARTUPINFO startupinfo;
PROCESS_INFORMATION process_information;
startupinfo.dwFlags = 0x1;
startupinfo.wShowWindow = 0x0;
startupinfo.cb = sizeof(startupinfo);
if (CreateProcessA ("test.exe", NULL, NULL, NULL, FALSE, 0, NULL, NULL, &startupinfo, &process_information))
{
cout << "[+] We have successfully launched the process\n" ;
cout << "[+] PID: " << process_information.dwProcessId;
WaitForSingleObject(process_information.hProcess, INFINITE);
CloseHandle(process_information.hProcess);
CloseHandle(process_information.hThread);
}
else {
cout << "[-] Error Code: " << GetLastError();
Sleep(3000);
}
return 0;
}
The above code works like a charm, but i want to apply OOP concepts in this project. So i wrote...
#include <iostream>
#include <windows.h>
using namespace std;
class CppDBG
{
public:
void load_exe();
};
void CppDBG :: load_exe()
{
STARTUPINFO startupinfo;
PROCESS_INFORMATION process_information;
startupinfo.dwFlags = 0x1;
startupinfo.wShowWindow = 0x0;
startupinfo.cb = sizeof(startupinfo);
if (CreateProcessA ("test.exe", NULL, NULL, NULL, FALSE, 0, NULL, NULL, &startupinfo, &process_information))
{
cout << "[+] We have successfully launched the process\n" ;
cout << "[+] PID: " << process_information.dwProcessId;
WaitForSingleObject(process_information.hProcess, INFINITE);
CloseHandle(process_information.hProcess);
CloseHandle(process_information.hThread);
}
else {
cout << "[-] Error Code: " << GetLastError();
Sleep(3000);
}
}
int main()
{
CppDBG dbg;
dbg.load_exe();
return 0;
}
the above code compiled correctly but is not running properly.
What am I missing?