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++ Question] Detecting Process

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

Joined: 29 Aug 2007
Posts: 391
Location: Finland

PostPosted: Sun Aug 10, 2008 9:13 am    Post subject: [C++ Question] Detecting Process Reply with quote

Hi. Im using Win32 Console and my problem is that I dont know how to make my program detect a process.


Example:
When the program is running and I open Notepad I want it to detect notepad.exe and if the program detects it, it writes "Notepad.exe found".

_________________
Programming in C++
(Or at least trying to Very Happy)
Back to top
View user's profile Send private message
GMZorita
Grandmaster Cheater Supreme
Reputation: 0

Joined: 21 Mar 2007
Posts: 1361

PostPosted: Sun Aug 10, 2008 9:31 am    Post subject: Reply with quote

FindWindow();

http://msdn.microsoft.com/en-us/library/ms633499(VS.85).aspx

_________________
Gone
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Sun Aug 10, 2008 9:37 am    Post subject: Reply with quote

That detects a window Rolling Eyes
He wants to detect the process itself.

CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS flag)
Process32First
Process32Next
_tcscmp (for process name check)

_________________
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Sun Aug 10, 2008 11:17 am    Post subject: Reply with quote

_tcscmp only works if he's using Unicode. Otherwise he should use strcmp.
_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Sun Aug 10, 2008 11:25 am    Post subject: Reply with quote

oib111 wrote:
_tcscmp only works if he's using Unicode. Otherwise he should use strcmp.
Isn't wcscmp the unicode one? Tcscmp is the one choosing the right one between ansi and unicode..?
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: Sun Aug 10, 2008 12:23 pm    Post subject: Reply with quote

_tcscmp is the TCHAR macro which will choose the correct function as needed based on compiler options.

Also, you should use _tcsicmp to perform a lowercase compare.

Example:

Code:
#include <windows.h>
#include <iostream>
#include <tlhelp32.h>
#include <tchar.h>
#include <stdio.h>

BOOL FoundNotepad()
{
   PROCESSENTRY32 pe32 = { sizeof( PROCESSENTRY32 ) };
   HANDLE hSnapshot = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );

   if( hSnapshot == INVALID_HANDLE_VALUE )
      return FALSE;

   if( Process32First( hSnapshot, &pe32 ) )
   {
      do{
         if( _tcsicmp( pe32.szExeFile, _T("notepad.exe") ) == 0 )
         {
            CloseHandle( hSnapshot );
            return TRUE;
         }
      }while( Process32Next( hSnapshot, &pe32 ) );
   }

   CloseHandle( hSnapshot );
   return FALSE;
}

int main()
{
   _tprintf_s( _T("Scanning for notepad... ") );

   while( !FoundNotepad() )
   {
      // Keep scanning until found...
      Sleep( 100 );
   }

   _tprintf_s( _T("Found!") );

   std::cin.sync();
   std::cin.ignore();
   return 0;
}

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
ssaccount
Master Cheater
Reputation: 0

Joined: 29 Aug 2007
Posts: 391
Location: Finland

PostPosted: Sun Aug 10, 2008 8:36 pm    Post subject: Reply with quote

Thanks for help Smile
_________________
Programming in C++
(Or at least trying to Very Happy)
Back to top
View user's profile Send private message
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Mon Aug 11, 2008 2:43 am    Post subject: Reply with quote

Wiccaan wrote:
_tcscmp is the TCHAR macro which will choose the correct function as needed based on compiler options.
Exactly what I meant :)
Back to top
View user's profile Send private message
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