View previous topic :: View next topic |
Author |
Message |
DEVCORE Cheater Reputation: 0
Joined: 11 Aug 2018 Posts: 28
|
Posted: Sun Sep 09, 2018 2:07 am Post subject: CreateToolHelp - Error Checking Problem |
|
|
Hey guys I am learning how to do this CreateTool32HelpSnapshot to get modules and process. I am stuck at the hProcessSnap, I want to check if the snapshot was successful. Why it is not working and not displaying when not successful anything?
Code: | #include "stdfax.h"
#include <iostream>
#include "Proc.h"
using namespace std;
DWORD GetProcessID(const wchar_t* ProcessName)
{
DWORD ProcessID = 0;
HANDLE hProcessSnap;
hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hProcessSnap == INVALID_HANDLE_VALUE)
{
cout << "Process Not Found" << endl;
}
else
{
PROCESSENTRY32 ProcessEntry;
ProcessEntry.dwSize = sizeof(ProcessEntry);
if (Process32First(hProcessSnap, &ProcessEntry))
{
do
{
if (!_wcsicmp(ProcessEntry.szExeFile, ProcessName))
{
ProcessID = ProcessEntry.th32ProcessID;
break;
}
} while (Process32Next(hProcessSnap, &ProcessEntry));
}
}CloseHandle(hProcessSnap);
return ProcessID;
} |
|
|
Back to top |
|
|
OldCheatEngineUser Whateven rank Reputation: 20
Joined: 01 Feb 2016 Posts: 1587
|
Posted: Sun Sep 09, 2018 3:58 am Post subject: |
|
|
i think its because your dowhile loop, it should work like this:
- create snapshot
- pass handle to process32first (first process will be system) so ...
- execute process32next and compare exefile with the given file name
_________________
About Me;
I Use CE Since Version 1.X, And Still Learning How To Use It Well!
Jul 26, 2020
STN wrote: | i am a sweetheart. |
|
|
Back to top |
|
|
atom0s Moderator Reputation: 198
Joined: 25 Jan 2006 Posts: 8517 Location: 127.0.0.1
|
Posted: Sun Sep 09, 2018 1:10 pm Post subject: |
|
|
If CreateToolhelp32Snapshot failed, use GetLastError right after it to find out why.
_________________
- Retired. |
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 458
Joined: 09 May 2003 Posts: 25295 Location: The netherlands
|
Posted: Sun Sep 09, 2018 1:55 pm Post subject: |
|
|
snapprocess always succeeds, so it never fails, therefore you will never get any prints, as the rest of your code doesn't print anything
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
|
DEVCORE Cheater Reputation: 0
Joined: 11 Aug 2018 Posts: 28
|
Posted: Sun Sep 09, 2018 7:52 pm Post subject: |
|
|
Dark Byte wrote: | snapprocess always succeeds, so it never fails, therefore you will never get any prints, as the rest of your code doesn't print anything |
So even if you do error checking you won’t any errors? But what if let’s say the process is called process.exe and that what the snapshot is ment to find. If that process is not open what will the snapshot find then? Sorry new to this
|
|
Back to top |
|
|
ParkourPenguin I post too much Reputation: 140
Joined: 06 Jul 2014 Posts: 4299
|
Posted: Sun Sep 09, 2018 8:41 pm Post subject: |
|
|
Normally, you should refer to documentation (i.e. MSDN) first; however, in this case, it doesn't specify what happens if the PID isn't valid.
Test it yourself and see what happens.
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 458
Joined: 09 May 2003 Posts: 25295 Location: The netherlands
|
Posted: Mon Sep 10, 2018 12:16 am Post subject: |
|
|
snap_process finds all processes, not just one. (That's why it doesn't error out)
The code you gave will just return 0 if it's not in the list (no prints at all)
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
|
|