Reputation: 203
I'm having trouble accessing the command-line arguments with using ASM. I've never encountered this problem before, so I'm a bit baffeled...
The assembler I'm using is NASM.
Paste from nasm -v:
NASM version 2.11 compiled on Dec 31 2013
As a linker, I'm using GOLINK as linker.
Relevant info from golink /h:
GoLink.Exe Version 0.28.0.0 - Copyright Jeremy Gordon 2002/12 - [email protected]
Here is the code I am trying to fix:
pop edx ; Return pointer
pop ebx ; ARGC
pop ecx ; ARGV
push ebx ; Should push ARGC onto the stack
push digit ; db '%d', 10, 0
call printf ; Call printf
I'm assembling this using:
nasm -f win32 file.asm
Linking using:
golink /console file.obj msvcrt.dll user32.dll kernel32.dll
(I'm using functions from msvcrt.dll, user32.dll and kernel32.dll later in the source)
There are no errors during assembling or linking.
When executing file.exe helloArg1 helloArg2, the output is:
2130567168
Which obviously is not the correct number of arguments...
I highly suspect that I've f-ed up something simple...
I'm currently running a x64 Win 7 (SP 1) box.
Any input would be greatly appreciated.
Upvotes: 0
Views: 907
Reputation: 61361
Use GetCommandLine()
.
According to this, the real startup function (WinMainCRTSTartup in GUI programs, mainCRTSTartup in console ones) doesn't receive any arguments from the caller. The command line that's eventually passed to main/WinMain is being retrieved via GetCommandLine()
within the RTL's implementation of xxxCRTStartup.
Upvotes: 2