Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[C++]FindWindow

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
myown
How do I cheat?
Reputation: 0

Joined: 11 Mar 2014
Posts: 9

PostPosted: Wed Mar 12, 2014 12:48 am    Post subject: [C++]FindWindow Reply with quote

why always when i try this code get error
HWND hWnd = FindWindow(0, "Call of Duty")

full code
Code:
#include <windows.h>
#include <iostream>

int main()
{
using namespace std;

int compteur_un = 0;
int compteur_deux = 0;
bool boucle = true;
cout << "Hello" << endl;
HWND hWnd = FindWindow(0, "Call of Duty")

if(hWnd == 0)

{

MessageBox(0, "Can't find window.", "Erreur", MB_OK|MB_ICONERROR);
}
else
{
DWORD proccess_ID;
GetWindowThreadProcessId(hWnd, &proccess_ID);
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, proccess_ID);
if(!hProcess)
{
MessageBox(0, "Can't open the process", "Erreur!", MB_OK|MB_ICONERROR);
}
return 0;
}

other code
Code:
#include <iostream>
#include <windows.h>

// FindWindow();
// GetWindowThreadProcessId();
// OpenProcess();
// WriteProcessMemory();
// CloseHandle();

using namespace std;

int main()

{

    int newValue = 700;

 

    HWND hWnd = FindWindow(0, "Call of Duty");

 

    if (hWnd == 0) {

        cerr << "Cannot find window." << endl;

    } else {

        DWORD pId;

        GetWindowThreadProcessId(hWnd, &pId);

        HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pId);

 

        if (!hProc) {

            cerr << "Cannot open process." << endl;

        } else {

            int isSuccessful = WriteProcessMemory(hProc, (LPVOID)0x000AFCC4, &newValue, (DWORD)sizeof(newValue), NULL);

 

            if (isSuccessful > 0) {

                clog << "Process memory written." << endl;

            } else {

                cerr << "Cannot write process memory." << endl;

            }

 

            CloseHandle(hProc);
         
      }

         
   }

     return 0;

}
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Wed Mar 12, 2014 3:02 pm    Post subject: Reply with quote

Perhaps the window name is not correct or the game has protection from being seen by the API.

Try using CreateToolhelp32Snapshot or PSAPI to locate the game via its process name instead.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites