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++] Listing all processes in a console window
Goto page Previous  1, 2
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Sat Jan 24, 2009 8:56 am    Post subject: Reply with quote

that way seems fine. but instead of:
Code:
curname = lppe.szExeFile;
         if(strcmp(procname, curname) == 0){
            return 0;
         }


you can just do:

Code:
if(!strcmp(procname, lppe.szExeFile))
{
  return 0;
}
Back to top
View user's profile Send private message
&Vage
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Jul 2008
Posts: 1053

PostPosted: Sat Jan 24, 2009 11:16 am    Post subject: Reply with quote

Ugh those std:: namespace annoys me, why not
Code:
using namespace std;
then you won't have to type std:: for every std function?
Back to top
View user's profile Send private message
Anden100
Grandmaster Cheater
Reputation: 0

Joined: 20 Apr 2007
Posts: 668

PostPosted: Sat Jan 24, 2009 1:25 pm    Post subject: Reply with quote

Slugsnack wrote:
that way seems fine. but instead of:
Code:
curname = lppe.szExeFile;
         if(strcmp(procname, curname) == 0){
            return 0;
         }


you can just do:

Code:
if(!strcmp(procname, lppe.szExeFile))
{
  return 0;
}


It doesent seem to work Sad

_void_ wrote:
Ugh those std:: namespace annoys me, why not
Code:
using namespace std;
then you won't have to type std:: for every std function?


I dunno, everyone says to not add them, so i do not O.o
Back to top
View user's profile Send private message
&Vage
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Jul 2008
Posts: 1053

PostPosted: Sat Jan 24, 2009 1:52 pm    Post subject: Reply with quote

Try...

Code:

if(strcmp(procname, &lppe.szExeFile) == 0)
Back to top
View user's profile Send private message
tombana
Master Cheater
Reputation: 2

Joined: 14 Jun 2007
Posts: 456
Location: The Netherlands

PostPosted: Sat Jan 24, 2009 2:35 pm    Post subject: Reply with quote

Also, at CreateToolhelp32Snapshot, you can also use TH32CS_SNAPPROCESS, instead of TH32CS_SNAPALL, because the latter one will also get other information which you don't need in this case.



_void_ wrote:
Try...

Code:

if(strcmp(procname, &lppe.szExeFile) == 0)

Don't think that would work. szExeFile is already a pointer to the string.
if( !strcmp(procname, lppe.szExeFile) ) should work
Back to top
View user's profile Send private message
&Vage
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Jul 2008
Posts: 1053

PostPosted: Sat Jan 24, 2009 2:50 pm    Post subject: Reply with quote

tombana wrote:
Also, at CreateToolhelp32Snapshot, you can also use TH32CS_SNAPPROCESS, instead of TH32CS_SNAPALL, because the latter one will also get other information which you don't need in this case.



_void_ wrote:
Try...

Code:

if(strcmp(procname, &lppe.szExeFile) == 0)

Don't think that would work. szExeFile is already a pointer to the string.
if( !strcmp(procname, lppe.szExeFile) ) should work

I like being careful since szExeFile is TCHAR and procname is char.
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Sat Jan 24, 2009 3:03 pm    Post subject: Reply with quote

look at my source, i do the same thing. btw try changing your character set to multi byte instead of unicode.
Back to top
View user's profile Send private message
Anden100
Grandmaster Cheater
Reputation: 0

Joined: 20 Apr 2007
Posts: 668

PostPosted: Sat Jan 24, 2009 3:26 pm    Post subject: Reply with quote

_void_ wrote:
tombana wrote:
Also, at CreateToolhelp32Snapshot, you can also use TH32CS_SNAPPROCESS, instead of TH32CS_SNAPALL, because the latter one will also get other information which you don't need in this case.



_void_ wrote:
Try...

Code:

if(strcmp(procname, &lppe.szExeFile) == 0)

Don't think that would work. szExeFile is already a pointer to the string.
if( !strcmp(procname, lppe.szExeFile) ) should work

I like being careful since szExeFile is TCHAR and procname is char.


main.cpp(25) : error C2664: 'strcmp' : cannot convert parameter 2 from 'CHAR (*)[260]' to 'const char *'

Nomatter what, the only thing that works, is the one i posted as a start...
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Sat Jan 24, 2009 4:08 pm    Post subject: Reply with quote

remove the &, it's already a pointer to the string.
Back to top
View user's profile Send private message
Anden100
Grandmaster Cheater
Reputation: 0

Joined: 20 Apr 2007
Posts: 668

PostPosted: Sat Jan 24, 2009 4:30 pm    Post subject: Reply with quote

slovach wrote:
remove the &, it's already a pointer to the string.


I know... it was just to tell him that it wouldn't work O.o
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Sat Jan 24, 2009 4:39 pm    Post subject: Reply with quote

i already told you what to do. unicode >> multibyte
Back to top
View user's profile Send private message
Skyance
Cheater
Reputation: 0

Joined: 07 Sep 2007
Posts: 46
Location: Israel

PostPosted: Sun Jan 25, 2009 2:04 am    Post subject: Reply with quote

Slugsnack wrote:
that way seems fine. but instead of:
Code:
curname = lppe.szExeFile;
         if(strcmp(procname, curname) == 0){
            return 0;
         }


you can just do:

Code:
if(!strcmp(procname, lppe.szExeFile))
{
  return 0;
}

True, however I find it very annoying...
I use !(condition) to check wether a condition is false, e.g. a function has failed.

strcmp returns 0 when the two strings are identical, not when it fails, so I prefer == 0 or at least == ERROR_SUCCESS. ("#define ERROR_SUCCESS 0")
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Sun Jan 25, 2009 3:28 am    Post subject: Reply with quote

don't shorten code just for the sake of it, if you're losing clarity, something is wrong.

== 0 definitely makes more sense to read in this case.
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
Goto page Previous  1, 2
Page 2 of 2

 
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