Using just the win32api.
Command line arg count stored in argc, args will be a pointer to a argc * 256 array containing the arguments (including program path as args[0]).



getclargs proto
convertclargs proto
freeclargs proto

.data

pwargs dd 0
argindex dd 0
pargs dd 0
argc dd 0

.code

start:
invoke getclargs
invoke convertclargs

; blah

invoke freeclargs
invoke ExitProcess, 0

getclargs proc
invoke GetCommandLineW
mov pwargs, eax
invoke CommandLineToArgvW, pwargs, addr argc
mov eax, [eax]
mov pwargs, eax
mov eax, argc
xor edx, edx
imul eax, 256
invoke VirtualAlloc, 0, eax, MEM_COMMIT, PAGE_READWRITE
mov pargs, eax
ret
getclargs endp

convertclargs proc uses esi edi
mov argindex, 0
mov eax, argindex
mov esi, pwargs
mov edi, pargs
.while eax < argc
invoke WideCharToMultiByte, 0, 0, esi, -1, edi, 256, 0, 0
lea esi, [esi + eax * 2]
add edi, 256
inc argindex
mov eax, argindex
.endw
ret
convertclargs endp

freeclargs proc
invoke VirtualFree, pargs, 0, MEM_RELEASE
ret
freeclargs endp
Posted on 2003-03-22 04:55:56 by grv575
grv575,

You can use also the getmainargs function from the C run-time DLLs:

http://www.asmcommunity.net/board/index.php?topic=9510&highlight=getmainargs

Regards,

Vortex
Posted on 2003-03-22 05:03:01 by Vortex
.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
Posted on 2003-03-22 12:04:12 by comrade
comrade: you assume you may modify the string returned by GetCommandLine but the documentation doesn't say you're allowed to do this. A quick test shows that the next call to GetCommandLine returns the same pointer and thus you're modifying window's internal data. Other code that relies on GetCommandLine to return the correct original string will subsequently fail.

Thomas
Posted on 2003-03-22 13:49:43 by Thomas
DIE
Posted on 2003-03-22 22:36:58 by comrade