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 


Retrieving Command Line Arguments from Win32 App

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
oib111
I post too much
Reputation: 0

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

PostPosted: Sat Jan 31, 2009 3:32 pm    Post subject: Retrieving Command Line Arguments from Win32 App Reply with quote

I'm trying to retrieve the command line arguments being passed to my Win32 application, but I can't seem to. This is my code:

Code:

//everything before
LPSTR CmdLine;

//command line check+message handler

int WINAPI WinMain (HINSTANCE hInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpCmdLine,
                    int nCmdShow)

{   
   CmdLine = lpCmdLine;
//...

_________________


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
killersamurai
Expert Cheater
Reputation: 0

Joined: 10 Sep 2007
Posts: 197
Location: Colorado

PostPosted: Sat Jan 31, 2009 3:52 pm    Post subject: Reply with quote

It's pretty easy. If it's multi-byte, you can just use lpCmdLine. It wont work with unicode. If it's unicode, you'll have to use GetCommandLine.
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Sat Jan 31, 2009 3:57 pm    Post subject: Reply with quote

Or just use _tWinMain and use LPTSTR lpCmdLine, and then you can use that parameter to get them.


Code:
BOOL WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nShowCmd)
{
   LPTSTR lpCommands = (LPTSTR)HeapAlloc(GetProcessHeap(), 0, sizeof(TCHAR)*(lstrlen(lpCmdLine)+1));
   if (lpCommands != NULL)
   {
      lstrcpy(lpCommands, lpCmdLine);
      // Do what you want with it...
      HeapFree(GetProcessHeap(), 0, (LPVOID)lpCommands);
   }
}

_________________
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: Sat Jan 31, 2009 4:29 pm    Post subject: Reply with quote

Lurc I'm not using Unicode. And killersamurai I am using multi-byte, so wouldn't just copying lpCmdLine to CmdLine work?
_________________


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
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Sat Jan 31, 2009 5:24 pm    Post subject: Reply with quote

Lurc wrote:

lstrcpy(lpCommands, lpCmdLine);


That's copying, and should work fine.

You're setting the pointer to your string as the pointer to the parameter, which is likely to go away as its scope is left.

_________________
Wiccaan wrote:

Oh jeez, watchout I'm a bias person! Locked.


Auto Assembly Tuts:
In Depth Tutorial on AA
Extended
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: Sat Jan 31, 2009 5:44 pm    Post subject: Reply with quote

Ok, I modified my code to:

Code:


//everything before
LPSTR lpCommands;

//stuff
WM_CREATE:
   if(strcmp(lpCommands, "/c") == 0) {
      //do stuff
   }
   if(strcmp(lpCommands, "/s") == 0) {
      //do stuff
   }

//...

int WINAPI WinMain (HINSTANCE hInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpCmdLine,
                    int nCmdShow)

{   
   strcpy(lpCommands, lpCmdLine);
//...


But now it's giving me runtime errors:

Call Stack wrote:

> IBIM Transfer.exe!strcat(unsigned char * dst=0x00161f4f, unsigned char * src=0xfffffffe) Line 223 Asm
IBIM Transfer.exe!WinMain(HINSTANCE__ * hInstance=0x00400000, HINSTANCE__ * hPrevInstance=0x00000000, char * lpCmdLine=0x00161f4f, int nCmdShow=1) Line 160 + 0x10 bytes C++
IBIM Transfer.exe!__tmainCRTStartup() Line 263 + 0x1b bytes C
kernel32.dll!7c817067()
[Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]


Output wrote:

'IBIM Transfer.exe': Loaded 'C:\Documents and Settings\OIB\My Documents\Visual Studio 2008\Projects\IBIM Transfer\Debug\IBIM Transfer.exe', Symbols loaded.
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\ntdll.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\kernel32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\user32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\gdi32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\comdlg32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\advapi32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\rpcrt4.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\secur32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83\comctl32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\msvcrt.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\shlwapi.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\shell32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\ws2_32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\ws2help.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\shimeng.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\imm32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\wbsys.dll', Binary was not built with debug information.
First-chance exception at 0x7c91b1fa in IBIM Transfer.exe: 0xC0000005: Access violation writing location 0x00000010.
'IBIM Transfer.exe': Unloaded 'C:\WINDOWS\system32\wbsys.dll'
'IBIM Transfer.exe': Unloaded 'C:\WINDOWS\system32\shimeng.dll'
First-chance exception at 0x004168d0 in IBIM Transfer.exe: 0xC0000005: Access violation writing location 0x00000000.
Unhandled exception at 0x004168d0 in IBIM Transfer.exe: 0xC0000005: Access violation writing location 0x00000000.


strcat.asm wrote:

byte_0:
mov [edi],dl
mov eax,[esp+8] ; return in eax pointer to dest string
pop edi
ret


Something's going wrong on:

Code:

mov eax,[esp+8]

_________________


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
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Sat Jan 31, 2009 6:14 pm    Post subject: Reply with quote

Did you allocate memory for your string?
_________________
Wiccaan wrote:

Oh jeez, watchout I'm a bias person! Locked.


Auto Assembly Tuts:
In Depth Tutorial on AA
Extended
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: Sat Jan 31, 2009 6:20 pm    Post subject: Reply with quote

samuri25404 wrote:
Did you allocate memory for your string?


Haha no I didn't. Well it's fixed. Thanks for all your help guys Smile

_________________


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
rapion124
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Mar 2007
Posts: 1095

PostPosted: Sat Jan 31, 2009 7:57 pm    Post subject: Reply with quote

I thought command-line was defined as PTSTR*:

Code:

int _tmain(int argc, _TCHAR argv[]) //int _tmain(int argc, PTSTR* argv)
{
...
}


Notice the brackets? They are interchangeable with a pointer. For example,
Code:

void DoSomething(DWORD aArguments[])

can be replaced by
Code:

void DoSomething(PDWORD aArguments)
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: Sat Jan 31, 2009 9:15 pm    Post subject: Reply with quote

Once again, I'm not programming in Unicode. Second, argv and argv are used for CLIs, not Win32. And I know arrays and pointers are interchangeable.
_________________


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
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Sat Jan 31, 2009 9:38 pm    Post subject: Reply with quote

It doesn't matter if your programming in UNICODE oib, the TCHAR routine takes care of that for you. It still doesn't matter though, just get the string from lpCmdLine and parse it for whatever your looking for.
_________________
Back to top
View user's profile Send private message
zoren123
Cheater
Reputation: 0

Joined: 28 Nov 2008
Posts: 39
Location: hdhdfgh

PostPosted: Sun Feb 01, 2009 2:19 am    Post subject: Reply with quote

i cant understand u people Question
_________________
gwqrwqerwqtwer
Back to top
View user's profile Send private message Yahoo Messenger
oib111
I post too much
Reputation: 0

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

PostPosted: Sun Feb 01, 2009 10:18 am    Post subject: Reply with quote

One quick little question? Is there anyway you can have Visual Studio execute your program with Command Line Arguments?
_________________


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
killersamurai
Expert Cheater
Reputation: 0

Joined: 10 Sep 2007
Posts: 197
Location: Colorado

PostPosted: Sun Feb 01, 2009 3:26 pm    Post subject: Reply with quote

Project-><solution name> Properties...->Configuration Properties-> Debugging . You'll then see Command Arguments
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 Feb 01, 2009 9:10 pm    Post subject: Reply with quote

killersamurai wrote:
Project-><solution name> Properties...->Configuration Properties-> Debugging . You'll then see Command Arguments


Thanks Smile

_________________


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
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