| View previous topic :: View next topic |
| Author |
Message |
Overload Master Cheater
Reputation: 0
Joined: 08 Feb 2008 Posts: 293
|
Posted: Thu May 08, 2008 11:57 pm Post subject: Help me with this code? |
|
|
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 |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Fri May 09, 2008 2:08 am Post subject: |
|
|
| 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 |
|
 |
Overload Master Cheater
Reputation: 0
Joined: 08 Feb 2008 Posts: 293
|
Posted: Fri May 09, 2008 9:36 am Post subject: |
|
|
ok, thanks noz. I was hoping someone like you would help me
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Fri May 09, 2008 1:34 pm Post subject: |
|
|
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 |
|
 |
Overload Master Cheater
Reputation: 0
Joined: 08 Feb 2008 Posts: 293
|
Posted: Fri May 09, 2008 5:21 pm Post subject: |
|
|
haha, ok. Yea, sorry about that
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 |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Fri May 09, 2008 5:34 pm Post subject: |
|
|
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 |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Fri May 09, 2008 6:44 pm Post subject: |
|
|
| Overload wrote: | haha, ok. Yea, sorry about that
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 |
|
 |
Overload Master Cheater
Reputation: 0
Joined: 08 Feb 2008 Posts: 293
|
Posted: Fri May 09, 2008 8:08 pm Post subject: |
|
|
| 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
But you said "add it before the loop". That would still be in the int main, but before the RUN = TRUE ?
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Fri May 09, 2008 8:17 pm Post subject: |
|
|
| 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 |
|
 |
Overload Master Cheater
Reputation: 0
Joined: 08 Feb 2008 Posts: 293
|
Posted: Fri May 09, 2008 10:22 pm Post subject: |
|
|
Okay, thanks Wiccaan
|
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Sat May 10, 2008 4:28 am Post subject: |
|
|
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 |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Sat May 10, 2008 12:59 pm Post subject: |
|
|
| 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 |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Sat May 10, 2008 1:01 pm Post subject: |
|
|
If you don't want to include Tchar.h you could also just define it yourself
#define _T(x) TEXT(x)
_________________
|
|
| Back to top |
|
 |
Overload Master Cheater
Reputation: 0
Joined: 08 Feb 2008 Posts: 293
|
Posted: Sat May 10, 2008 1:05 pm Post subject: |
|
|
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
|
|
| Back to top |
|
 |
|