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++] Need help > a function to return a PID

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
educofu
Expert Cheater
Reputation: 3

Joined: 21 Aug 2009
Posts: 171
Location: Brazil,MG,OP

PostPosted: Wed Jan 12, 2011 11:51 am    Post subject: [C++] Need help > a function to return a PID Reply with quote

i have done the following function:

Code:

int AttachToWindow(char* WindowName)
{
    hWindow = FindWindow(0,  WindowName);     
    GetWindowThreadProcessId(hWindow, &dwPID);
    hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwPID);
   
    if(!hWindow || !hProcess)
    {
         cout << "Error opening the process" << endl;
         return 0;
         }

    else
    {
         cout << name << " opened!" << endl;
         return 1;
         }
    }


but now im having trouble creating the function:

AttachToProcess(char* ProcessName)

i need something like the first function AttachToWindow(char* WindowName), so i can enter a Process name (like "cmd.exe").

can some 1 help me with that?

_________________
"I finally started thinking outside of the box, only to find myself in a larger box."
Back to top
View user's profile Send private message MSN Messenger
Dacnomania
Expert Cheater
Reputation: 1

Joined: 03 Sep 2010
Posts: 124

PostPosted: Wed Jan 12, 2011 12:57 pm    Post subject: Reply with quote

Trying to achieve what I've tried to achieve, failed alongside the failed help of our comrads. xP
Back to top
View user's profile Send private message Send e-mail AIM Address
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Wed Jan 12, 2011 4:03 pm    Post subject: Reply with quote

EnumProcesses or CreateToolHelp32Snapshot with Process32First/Next
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 204

Joined: 25 Jan 2006
Posts: 8580
Location: 127.0.0.1

PostPosted: Thu Jan 13, 2011 1:17 pm    Post subject: Reply with quote

On a side note to your currently posted code:

Code:

    hWindow = FindWindow(0,  WindowName);     
    GetWindowThreadProcessId(hWindow, &dwPID);
    hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwPID);

    if(!hWindow || !hProcess)


It is completely pointless to have error checking after attempting to use a variable. Don't bother including error checking if you aren't going to use it properly.

Also don't use PROCESS_ALL_ACCESS either, specify the needed flags.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
educofu
Expert Cheater
Reputation: 3

Joined: 21 Aug 2009
Posts: 171
Location: Brazil,MG,OP

PostPosted: Fri Jan 14, 2011 4:24 pm    Post subject: Reply with quote

Just found the answer. see at: http://forum.cheatengine.org/viewtopic.php?t=529527

@Wiccan, u right. just modifyed that.

_________________
"I finally started thinking outside of the box, only to find myself in a larger box."
Back to top
View user's profile Send private message MSN Messenger
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