News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Using CommandLine

Started by shadow, August 15, 2005, 09:20:23 AM

Previous topic - Next topic

shadow

Hi again!  :P
Does does anyone know any good methods for extracting command line parameters from the path returned by GetCommandLine?  I've been comparing the entire string with the same string+the parameter, but I know there is a more efficient way.  Is there someway I can just read whats after the delimiter?  ::)

thanks!  :wink

Vortex

Hi Shadow,

Here is an example for you, check the attachment to view the command line parser function ParseCmdLine , you need to allocate 512 bytes as buffer for the function.


.386
.model flat, stdcall
option casemap :none

      include \masm32\include\windows.inc
      include \masm32\include\user32.inc
      include \masm32\include\kernel32.inc
      include \masm32\include\masm32.inc

      includelib \masm32\lib\user32.lib
      includelib \masm32\lib\masm32.lib
      includelib \masm32\lib\kernel32.lib     

ParseCmdLine PROTO :DWORD

.data
template           db 'Command line parameter %d = %s',13,10,0

.data?
buffer1      db 512 dup(?)
buffer2      db 512 dup(?)

.code
start:
       
   push   esi
   push   edi
   push   ebx
   mov   esi,OFFSET buffer1
   invoke   ParseCmdLine,esi       
    mov   edi,eax
   xor   ebx,ebx
@@:
   invoke   wsprintf,ADDR buffer2,ADDR template,ebx,DWORD PTR [esi]
   invoke   StdOut,ADDR buffer2
   add   esi,4
   inc   ebx
   dec   edi
    jnz   @b
@@:
   pop   ebx
   pop   edi
   pop   esi
   invoke   ExitProcess,0

END start



\masm32\bin\ml /c /coff Test.asm
\masm32\bin\polink /SUBSYSTEM:CONSOLE Test.obj parsecmdline.obj


[attachment deleted by admin]

Jeff

i just happen to have one that could handle "long arguments" too.  it may not be as compact or optimized as vortex's but with the tests ive run, i catches even the wierdest lines too.  :)  sorry about the lack of comments but you will get the idea.

[attachment deleted by admin]

P1

The MASM32 Library has some CL tools too!!

Regards,  P1  :8)