Like when i start a exe "filename.exe -switch1 -switch2 etc"?
Thanks.
Thanks.
You can easily get the command line using:
GetCommandLine API:
The GetCommandLine function returns a pointer to the command-line string for the current process.
LPTSTR GetCommandLine(VOID)
Parameters
This function has no parameters.
Return Values
The return value is a pointer to the command-line string for the current process.
Remarks
Non-Unicode console processes written in C can use the argc and argv arguments to access the command-line arguments. The parameters of the command-line string, excluding the program name, are also available to such non-Unicode applications as a parameter of the WinMain function. The reason for the Unicode exclusion from these options is that WinMain, argc, and argv use the LPSTR data type for parameters, not the LPTSTR datatype.
--------------
And from your WinMain:
invoke GetCommandLine ; returns a pointer to the command line in eax
mov CommandLine, eax
GetCommandLine API:
The GetCommandLine function returns a pointer to the command-line string for the current process.
LPTSTR GetCommandLine(VOID)
Parameters
This function has no parameters.
Return Values
The return value is a pointer to the command-line string for the current process.
Remarks
Non-Unicode console processes written in C can use the argc and argv arguments to access the command-line arguments. The parameters of the command-line string, excluding the program name, are also available to such non-Unicode applications as a parameter of the WinMain function. The reason for the Unicode exclusion from these options is that WinMain, argc, and argv use the LPSTR data type for parameters, not the LPTSTR datatype.
--------------
And from your WinMain:
WinMain proc hInst :DWORD,
hPrevInst :DWORD,
[COLOR=blue]CmdLine :DWORD[/COLOR] ,
CmdShow :DWORD
If you do get command-line, you still need to slice it into parts:
would point to first parameter (executable name), to second parameter (-switch1), etc. C-style.
.data
argc dd ?
argv dd 16 dup (?)
.code
ProcessCmdLine proc
push edi
push esi
push ebx
call GetCommandLine
mov esi, eax
mov edi, OFFSET argv
xor ecx, ecx
xor ebx, ebx
xor edx, edx
@@cmss: mov eax, esi
mov dl, 20h
cmp byte ptr [esi], 22h
sete cl
lea edx, [edx+ecx*2]
add eax, ecx
stosd
@@cm00: inc esi
cmp byte ptr [esi], 0
je @@cm01
cmp byte ptr [esi], dl
jne @@cm00
mov byte ptr [esi], 0
add esi, ecx
inc esi
cmp byte ptr [esi], 0
je @@cm01
inc [argc]
jmp @@cmss
@@cm01: pop ebx
pop esi
pop edi
inc [argc]
ret
ProcessCmdLine endp
would point to first parameter (executable name), to second parameter (-switch1), etc. C-style.
Afternoon, Ghirai.
Also remember that, if you drag'n'drop a file onto an exe, you won't get the correct commandline supplied.
To make sure the commandline is supplied, drag'n'drop a file onto a ShortCut of your exe.
Cheers,
Scronty
Also remember that, if you drag'n'drop a file onto an exe, you won't get the correct commandline supplied.
To make sure the commandline is supplied, drag'n'drop a file onto a ShortCut of your exe.
Cheers,
Scronty
Thanks a lot guys for the quick answer.
Cool, thanks.