Raised This Month: $ Target: $400
 0% 

Help with c++ code


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
padilha007
Senior Member
Join Date: Jul 2008
Old 10-10-2012 , 23:42   Help with c++ code
Reply With Quote #1

I am creating a dll and I have a problem with comparing char. I'm very new to c++ and I am frustrated with my problem:

PHP Code:
unsigned long CGamer::GetProcessPathByName(char *PathName)
{
    
PROCESSENTRY32 pe;
    
HANDLE thSnapshot;
    
BOOL retvalProcFound false;
    
pe.th32ProcessID 0;

    
thSnapshot CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS0);

    if(
thSnapshot == INVALID_HANDLE_VALUE)
    {
        return 
0;
    }

    
pe.dwSize sizeof(PROCESSENTRY32);

    
retval Process32First(thSnapshot, &pe);

    while(
retval)
    {
        
char nameProc[MAX_PATH];

        
HANDLE h OpenProcess(PROCESS_QUERY_INFORMATION PROCESS_VM_READFALSEpe.th32ProcessID);

        
// Check
        
GetProcessImageFileName(h, (LPWSTR)nameProcsizeof(nameProc)/sizeof(*nameProc));

        
// Comparation
        
if ( PathName is in nameProc )
                      ...

        
retval    Process32Next(thSnapshot,&pe);
        
pe.dwSize sizeof(PROCESSENTRY32);
    }

    return 
0;

I simply can not know if the word Pathname is in nameProc. Sorry for the ridiculous question.
__________________


Last edited by padilha007; 10-11-2012 at 00:20.
padilha007 is offline
micapat
Veteran Member
Join Date: Feb 2010
Location: Nyuu, nyuu (France).
Old 10-11-2012 , 01:39   Re: Help with c++ code
Reply With Quote #2

http://www.cplusplus.com/reference/c...string/strstr/
__________________
micapat is offline
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 10-11-2012 , 10:38   Re: Help with c++ code
Reply With Quote #3

PHP Code:
char pF "Something", * pS "Other Thing";
if( !
strcmppFpS ) ) { /* Equals */ }
else { 
/* ... */ 
strcasecmp transforms all characters to lower case so R will be equal with r.

strcasecontain checks whether ccSubString is included in ccString.

PHP Code:
bool strcasecontain( const char *ccString, const char *ccSubString )
{
    const 
char *ccCopyOfString ccString, *ccSecondCopyOfString ccString, *ccCopyOfSubString ccSubString, *ccSecondCopyOfSubString ccSubString;

    while( *
ccSecondCopyOfString )
    {
        if( 
tolower( *ccSecondCopyOfString ) == tolower( *ccCopyOfSubString ) )
        {
            
ccSecondCopyOfString++;

            if( !*++
ccCopyOfSubString )
                return 
true;
        }

        else
        {
            
ccSecondCopyOfString = ++ccCopyOfString;

            
ccCopyOfSubString ccSecondCopyOfSubString;
        }
    }

    return 
false;

__________________

Last edited by claudiuhks; 10-11-2012 at 10:40.
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 10-11-2012 , 11:50   Re: Help with c++ code
Reply With Quote #4

Quote:
Originally Posted by claudiuhks View Post
PHP Code:
char pF "Something", * pS "Other Thing";
if( !
strcmppFpS ) ) { /* Equals */ }
else { 
/* ... */ 
strcasecmp transforms all characters to lower case so R will be equal with r.

strcasecontain checks whether ccSubString is included in ccString.

PHP Code:
bool strcasecontain( const char *ccString, const char *ccSubString )
{
    const 
char *ccCopyOfString ccString, *ccSecondCopyOfString ccString, *ccCopyOfSubString ccSubString, *ccSecondCopyOfSubString ccSubString;

    while( *
ccSecondCopyOfString )
    {
        if( 
tolower( *ccSecondCopyOfString ) == tolower( *ccCopyOfSubString ) )
        {
            
ccSecondCopyOfString++;

            if( !*++
ccCopyOfSubString )
                return 
true;
        }

        else
        {
            
ccSecondCopyOfString = ++ccCopyOfString;

            
ccCopyOfSubString ccSecondCopyOfSubString;
        }
    }

    return 
false;

Wouldn't it just be easier to tolower the entirety of both strings, then run strstr on them?
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 10-11-2012 at 11:52.
Powerlord is offline
padilha007
Senior Member
Join Date: Jul 2008
Old 10-11-2012 , 13:12   Re: Help with c++ code
Reply With Quote #5

damn i'm so noob, i cant get it!

PHP Code:
unsigned long CGame::GetProcessPathByName(char *PathName)
{
    
PROCESSENTRY32 pe;
    
HANDLE thSnapshot;
    
BOOL retvalProcFound false;
    
pe.th32ProcessID 0;

    
thSnapshot CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS0);

    if(
thSnapshot == INVALID_HANDLE_VALUE)
    {
        return 
0;
    }

    
pe.dwSize sizeof(PROCESSENTRY32);

    
retval Process32First(thSnapshot, &pe);

    while(
retval)
    {
        
// Get
        
HANDLE h OpenProcess(PROCESS_QUERY_INFORMATION PROCESS_VM_READFALSEpe.th32ProcessID);

        
// Name Proc
        
char nameProc[MAX_PATH];

        
// Check
        
GetProcessImageFileName(h, (LPWSTR)nameProcMAX_PATH);

        if ( 
strcasecontain(nameProcPathName) )
            
MessageBox(0, (LPWSTR)nameProcL"Found"MB_OK);

        
// Next
        
retval    Process32Next(thSnapshot,&pe);
        
pe.dwSize sizeof(PROCESSENTRY32);
    }

    return 
0;
}

bool strcasecontain( const char *ccString, const char *ccSubString )
{
    const 
char *ccCopyOfString ccString, *ccSecondCopyOfString ccString, *ccCopyOfSubString ccSubString, *ccSecondCopyOfSubString ccSubString;

    while( *
ccSecondCopyOfString )
    {
        if( 
tolower( *ccSecondCopyOfString ) == tolower( *ccCopyOfSubString ) )
        {
            
ccSecondCopyOfString++;

            if( !*++
ccCopyOfSubString )
                return 
true;
        }

        else
        {
            
ccSecondCopyOfString = ++ccCopyOfString;

            
ccCopyOfSubString ccSecondCopyOfSubString;
        }
    }

    return 
false;

__________________


Last edited by padilha007; 10-11-2012 at 13:12.
padilha007 is offline
micapat
Veteran Member
Join Date: Feb 2010
Location: Nyuu, nyuu (France).
Old 10-11-2012 , 13:28   Re: Help with c++ code
Reply With Quote #6

Reverse the order of these functions in your file. Or add the prototype of strcasecontain.

Btw you must import tolower( ).
__________________

Last edited by micapat; 10-11-2012 at 13:30.
micapat is offline
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 10-11-2012 , 13:48   Re: Help with c++ code
Reply With Quote #7

PHP Code:
#include <ctype.h> /* tolower */

bool strcasecontain( const char *, const char * );

//
// Your code here
//

bool strcasecontain( const char a, const char ) {
  
// This function's code

__________________

Last edited by claudiuhks; 10-11-2012 at 13:48.
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:24.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode