View previous topic :: View next topic |
Author |
Message |
educofu Expert Cheater
Reputation: 3
Joined: 21 Aug 2009 Posts: 171 Location: Brazil,MG,OP
|
Posted: Wed Jan 12, 2011 11:51 am Post subject: [C++] Need help > a function to return a PID |
|
|
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 |
|
 |
Dacnomania Expert Cheater
Reputation: 1
Joined: 03 Sep 2010 Posts: 124
|
Posted: Wed Jan 12, 2011 12:57 pm Post subject: |
|
|
Trying to achieve what I've tried to achieve, failed alongside the failed help of our comrads. xP
|
|
Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Wed Jan 12, 2011 4:03 pm Post subject: |
|
|
EnumProcesses or CreateToolHelp32Snapshot with Process32First/Next
|
|
Back to top |
|
 |
atom0s Moderator
Reputation: 204
Joined: 25 Jan 2006 Posts: 8580 Location: 127.0.0.1
|
Posted: Thu Jan 13, 2011 1:17 pm Post subject: |
|
|
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 |
|
 |
educofu Expert Cheater
Reputation: 3
Joined: 21 Aug 2009 Posts: 171 Location: Brazil,MG,OP
|
Posted: Fri Jan 14, 2011 4:24 pm Post subject: |
|
|
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 |
|
 |
|