1st... Welcome :bg
2nd...
:'( I made little program using parametrs and I have problem with making condition:
.386
.MODEL FLAT, STDCALL
OPTION CASEMAP:NONE
INCLUDE \masm32\include\windows.inc
INCLUDE \masm32\include\user32.inc
INCLUDE \masm32\include\kernel32.inc
INCLUDELIB \masm32\lib\user32.lib
INCLUDELIB \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib
include \masm32\include\masm32.inc
.DATA
buffer BYTE 128 (0)
lpMsg db "Error",0
lpCaption db "Program fail",0
lpOK db "OK",0
.CODE
start:
INVOKE GetCL,1,ADDR buffer
.IF buffer==2
INVOKE MessageBox,0,lpMsg,lpCaption,MB_ICONERROR ;statement #1
.ELSE
INVOKE MessageBox,0,ADDR buffer,ADDR lpOK,MB_ICONINFORMATION ; second
INVOKE WinExec,ADDR buffer,SW_SHOW ; statement
.endif
INVOKE ExitProcess,0
END start
Masm helper wrote:
Quote
GetCl will retreive the argument specified in the procedure call and return the argument in the buffer specified.(...)
Return values
1 = successful operation
2 = no argument exists at specified arg number
3 = non matching quotation marks
4 = empty quotation marks
So I set condition which compares buffer with 2, because i want to see message when there is no parameter,but (there is problem) when I run my application without parameter it shows "GOOD" message (MessageBox,0,ADDR buffer,ADDR lpOK,MB_ICONINFORMATION) too.
My question:
With what I have to compare buffer if I want to execute statement #1? :red
I apologize for my bad english :red
GetCL return value is returned in eax, so you need to check if eax is 2. If there is argument then the buffer has it, and the return value in eax is 1.
invoke GetCL, 1, ADDR buffer
.if eax == 2
;Here show message that no argument exists!
.else
;Do what ever
.endif
Ok i changed it, but still doesn't work :(
LOOK (http://img476.imageshack.us/img476/6699/masmeax7om.jpg)
You forgot to use ADDR at the first MessageBox.
Ohh thanx :red - Unfortunately it doesn't change situation. Notice that shows MsgBox with MB_ICONINFORMATION, but it should show MesgBox with MB_ICONERROR
EDIT:
Ok, wroking :bdg . I put:
.if eax!=1
instead of
.if eax==2
But still don't know why buffer doesn't return 2 if program ran without parametrs :dazzled:
Hi herman,
Welcome on board. When you are testing a register that can return multiple values try something like this.
; your GetCL code.
.if eax == 1
; ok result
.elseif eax == 2
; error
.elseif eax == 3
; error
.elseif eax == 4
; error
.endif
You can be a bit more efficient depending on what you want to test but this will give you the range of results.
For me your code works. I just changed from your original code to check if eax == 2 and added the ADDR to first MessageBox line and it displays error message with ICONERROR if the cmdline is empty.
Check full code here
.386
.MODEL FLAT, STDCALL
OPTION CASEMAP:NONE
INCLUDE \masm32\include\windows.inc
INCLUDE \masm32\include\user32.inc
INCLUDE \masm32\include\kernel32.inc
INCLUDELIB \masm32\lib\user32.lib
INCLUDELIB \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib
include \masm32\include\masm32.inc
.DATA
buffer BYTE 128 (0)
lpMsg db "Error",0
lpCaption db "Program fail",0
lpOK db "OK",0
.CODE
start:
INVOKE GetCL,1,ADDR buffer
.IF eax==2
INVOKE MessageBox,0,ADDR lpMsg, ADDR lpCaption,MB_ICONERROR ;statement #1
.ELSE
INVOKE MessageBox,0,ADDR buffer,ADDR lpOK,MB_ICONINFORMATION ; second
INVOKE WinExec,ADDR buffer,SW_SHOW ; statement
.endif
INVOKE ExitProcess,0
END start
For one thing
.DATA
buffer BYTE 128 (0)
needs to be
.DATA
buffer BYTE 128 DUP(0)
I missed that completely, and when I tested it with some parameters, they were so short that they only overwrite lpMsg and/or lpCaption variables and thus everything seemed to be ok.
SamiP,
We have all been there. :bg