News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

cant move return value of eax in to a buffer?

Started by ltech19, July 15, 2012, 12:55:06 AM

Previous topic - Next topic

ltech19

.data

myName db 255 dup (0)

.code

start:

Invoke GetCommandLine
mov myName, eax

end start


why does this not work? i cannot mov eax in to MyName buffer..

hutch--

Won't work, you need a DWORD sized memory operand for EAX. What you "should" be returning is a POINTER to the address of the string buffer.

Now in the case of "GetCommandLine" it actually returns a POINTER to a buffer that you do NOT allocate, the system does that. What you can do is copy it to a buffer of your own once you know how long the command line is and allocate a buffer of that size. In this context you use dynamic memory like GlobalAlloc or one of the other allocation strategies.

jj2007

For testing.

include \masm32\include\masm32rt.inc

.data?
myName dd ?
FirstArg dd ?

.code
start: invoke GetCommandLine
mov myName, eax
MsgBox 0, myName, "The raw commandline:", MB_OK
sub esp, 400 ; create a buffer
mov FirstArg, esp ; store address of buffer
invoke GetCL, 1, esp ; Masm32 library function
MsgBox 0, FirstArg, "Arg1:", MB_OK
add esp, 400
exit
end start