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 


CreateToolHelp - Error Checking Problem

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

Joined: 11 Aug 2018
Posts: 28

PostPosted: Sun Sep 09, 2018 2:07 am    Post subject: CreateToolHelp - Error Checking Problem Reply with quote

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
View user's profile Send private message
OldCheatEngineUser
Whateven rank
Reputation: 20

Joined: 01 Feb 2016
Posts: 1587

PostPosted: Sun Sep 09, 2018 3:58 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
atom0s
Moderator
Reputation: 198

Joined: 25 Jan 2006
Posts: 8517
Location: 127.0.0.1

PostPosted: Sun Sep 09, 2018 1:10 pm    Post subject: Reply with quote

If CreateToolhelp32Snapshot failed, use GetLastError right after it to find out why.
_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Dark Byte
Site Admin
Reputation: 458

Joined: 09 May 2003
Posts: 25283
Location: The netherlands

PostPosted: Sun Sep 09, 2018 1:55 pm    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
DEVCORE
Cheater
Reputation: 0

Joined: 11 Aug 2018
Posts: 28

PostPosted: Sun Sep 09, 2018 7:52 pm    Post subject: Reply with quote

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
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 140

Joined: 06 Jul 2014
Posts: 4289

PostPosted: Sun Sep 09, 2018 8:41 pm    Post subject: Reply with quote

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
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

Joined: 09 May 2003
Posts: 25283
Location: The netherlands

PostPosted: Mon Sep 10, 2018 12:16 am    Post subject: Reply with quote

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
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