Heya, fellow hackers and hack-users.
Not sure whether to post here or in coders...
I got a little problem I want to share with you.
I got this code
Code
#include <iostream>
#include <windows.h>
HWND hwnd;
PDWORD procId;
HANDLE hProc;
int main()
{
hwnd = FindWindow(NULL, "Game name I wont tell till its finished");
if (!hwnd)
{
cout << "Game window not found." << endl;
Sleep(3000);
exit(-1);
}
GetWindowThreadProcessId(hwnd, procId);
hProc = OpenProcess(PROCESS_ALL_ACCESS, false, (DWORD) procId);
if (!hProc)
{
cout << "Could not open game." << endl;
Sleep(3000);
exit(-1);
}
}
It always says "Could not open game."
While debugging I found out that procId seems to be 0 at all times. When calling GetLastError it returned 18 (ERROR_NO_MORE_FILES)... and it didn't cared about where I called it, even right at the beginning.
I googled. And I found that it always returns 0 when called from a service (which I don't think I got).
I recently switched from Code::Blocks to g++. Is there the problem? Or is it because I'm calling it from int main instead of BOOL WinMain?
Is there a way to bypass this?
Thank you.
Edit: Solved!
I got a goddamn typo and than got confused.
Working code:
Code
#include <iostream>
#include <windows.h>
HWND hwnd;
DWORD procId; // change here
HANDLE hProc;
int main()
{
hwnd = FindWindow(NULL, "Game name I wont tell till its finished");
if (!hwnd)
{
cout << "Game window not found." << endl;
Sleep(3000);
exit(-1);
}
GetWindowThreadProcessId(hwnd, &procId); // change here
hProc = OpenProcess(PROCESS_ALL_ACCESS, false, (DWORD) procId);
if (!hProc)
{
cout << "Could not open game." << endl;
Sleep(3000);
exit(-1);
}
}