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 


Help me with this code?

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

Joined: 08 Feb 2008
Posts: 293

PostPosted: Thu May 08, 2008 11:57 pm    Post subject: Help me with this code? Reply with quote

Whats wrong with this code? And i think you guys will figure out what i am trying to do...

Code:
#include "Windows.h"

volatile bool RUN = FALSE;

int CreateProcessWrapper( LPTSTR process_name )
{
   STARTUPINFO si;
   PROCESS_INFORMATION pi;

   ZeroMemory( &si, sizeof(si) );
   si.cb = sizeof(si);
   ZeroMemory( &pi, sizeof(pi) );
   int retval = CreateProcess( process_name, NULL, NULL, NULL, FALSE, NULL, NULL, NULL, &si, &pi);
   CloseHandle( pi.hProcess );
   CloseHandle( pi.hThread );
   return retval;
}

int main(int argc, char* argv[])
{
   RUN = TRUE;
   while ( RUN )
   {
      if ( FindWindow("Notepad", "Untitled - Notepad") == NULL )
         CreateProcessWrapper("C:\\yourprogrampathhere");
      Sleep(100);
   }
   return 0;
}
Back to top
View user's profile Send private message MSN Messenger
Noz3001
I'm a spammer
Reputation: 26

Joined: 29 May 2006
Posts: 6220
Location: /dev/null

PostPosted: Fri May 09, 2008 2:08 am    Post subject: Reply with quote

Code:
#include "windows.h"

bool RUN = true;

int CreateProcessWrapper( LPTSTR process_name )
{
   STARTUPINFO si;
   PROCESS_INFORMATION pi;

   ZeroMemory( &si, sizeof(si) );
   si.cb = sizeof(si);
   ZeroMemory( &pi, sizeof(pi) );
   int retval = CreateProcess( process_name, NULL, NULL, NULL, FALSE, NULL, NULL, NULL, &si, &pi);
   CloseHandle( pi.hProcess );
   CloseHandle( pi.hThread );
   return retval;
}

int main(int argc, char* argv[])
{
   while ( RUN )
   {
      if ( FindWindow( L"Notepad", NULL ) == NULL ) { // Why check that Notepad is not running?
         CreateProcessWrapper( L"C:\\test.exe" );
       RUN = false;
      }

      Sleep(10);
   }

   return 0;
}


Your problem was you were passing char[] to LPTSTR?

Oh and i like the volatile keyword, it's cool =D
Back to top
View user's profile Send private message MSN Messenger
Overload
Master Cheater
Reputation: 0

Joined: 08 Feb 2008
Posts: 293

PostPosted: Fri May 09, 2008 9:36 am    Post subject: Reply with quote

ok, thanks noz. I was hoping someone like you would help me Smile
Back to top
View user's profile Send private message MSN Messenger
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Fri May 09, 2008 1:34 pm    Post subject: Reply with quote

Just a suggestion, next time you post code and ask for help with it, it kinda helps if you say whats the issue lol.
_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Overload
Master Cheater
Reputation: 0

Joined: 08 Feb 2008
Posts: 293

PostPosted: Fri May 09, 2008 5:21 pm    Post subject: Reply with quote

haha, ok. Yea, sorry about that Embarassed

EDIT:

Why do you need the L in the code?

Code:
if ( FindWindow( L"Notepad", NULL ) == NULL ) { // Why check that Notepad is not running?
         CreateProcessWrapper( L"C:\\test.exe" );


like in the
Code:
FindWindow(L"Notepad", NULL)


What does the L mean?


EDIT 2:

And how can i make it userdefined, so it does FindWindow on what the user specifies, and Creates the process if NULL?
I just tried it, and it doesn't seem to work =/


Last edited by Overload on Fri May 09, 2008 5:42 pm; edited 1 time in total
Back to top
View user's profile Send private message MSN Messenger
oib111
I post too much
Reputation: 0

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

PostPosted: Fri May 09, 2008 5:34 pm    Post subject: Reply with quote

It's for unicode, but only if your using a unicode character set. If you're using multi-byte don't use L.
_________________


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
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Fri May 09, 2008 6:44 pm    Post subject: Reply with quote

Overload wrote:
haha, ok. Yea, sorry about that Embarassed

EDIT:

Why do you need the L in the code?

Code:
if ( FindWindow( L"Notepad", NULL ) == NULL ) { // Why check that Notepad is not running?
         CreateProcessWrapper( L"C:\\test.exe" );


like in the
Code:
FindWindow(L"Notepad", NULL)


What does the L mean?


EDIT 2:

And how can i make it userdefined, so it does FindWindow on what the user specifies, and Creates the process if NULL?
I just tried it, and it doesn't seem to work =/


L is for unicode strings, as Oib said. Some info on it here:
http://msdn.microsoft.com/en-us/library/69ze775t(VS.80).aspx

As for the user-defined window, have the project accept user input before you go into the loop. You can use the iostream header to accept input/output:

Code:
#include <iostream>

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

Joined: 08 Feb 2008
Posts: 293

PostPosted: Fri May 09, 2008 8:08 pm    Post subject: Reply with quote

Wiccaan wrote:


As for the user-defined window, have the project accept user input before you go into the loop. You can use the iostream header to accept input/output:

Code:
#include <iostream>


Okay. Thanks Wiccaan Smile

But you said "add it before the loop". That would still be in the int main, but before the RUN = TRUE ?
Back to top
View user's profile Send private message MSN Messenger
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Fri May 09, 2008 8:17 pm    Post subject: Reply with quote

Code:
int main(int argc, char* argv[])
{

   // ADD IT HERE

   while ( RUN )
   {
        // .. other code here...


Add it before the while, like seen above.

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

Joined: 08 Feb 2008
Posts: 293

PostPosted: Fri May 09, 2008 10:22 pm    Post subject: Reply with quote

Okay, thanks Wiccaan Smile
Back to top
View user's profile Send private message MSN Messenger
Noz3001
I'm a spammer
Reputation: 26

Joined: 29 May 2006
Posts: 6220
Location: /dev/null

PostPosted: Sat May 10, 2008 4:28 am    Post subject: Reply with quote

I would have used _TEXT instead of L but my compiler wasn't in a very good mood yesterday.

Am I correct in saying _TEXT() will convert the string to unicode only if unicode is set in the compiler options?
Back to top
View user's profile Send private message MSN Messenger
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Sat May 10, 2008 12:59 pm    Post subject: Reply with quote

noz3001 wrote:
I would have used _TEXT instead of L but my compiler wasn't in a very good mood yesterday.

Am I correct in saying _TEXT() will convert the string to unicode only if unicode is set in the compiler options?


Yes. But it's easier to use _T( ) since its shorter and takes up less space. (Visually)

TCHAR.h
Code:
#define _T(x)       __T(x)
#define _TEXT(x)    __T(x)


And if you don't want to include and use the TCHAR functions, you can use just, 'TEXT( )' which is defined in WinNT.h and is handled with an ifdef block for the compiler setting automatically:

WinNT.h
Code:
#define TEXT(quote) __TEXT(quote)   // r_winnt

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Sat May 10, 2008 1:01 pm    Post subject: Reply with quote

If you don't want to include Tchar.h you could also just define it yourself Wink

#define _T(x) TEXT(x)

_________________
Back to top
View user's profile Send private message
Overload
Master Cheater
Reputation: 0

Joined: 08 Feb 2008
Posts: 293

PostPosted: Sat May 10, 2008 1:05 pm    Post subject: Reply with quote

Okay, thanks a lot you guys.

I think i can edit it some from here, to fit my needs :p

Though, i know i will need you guy's help again at some point Wink
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