how would i create a windows console app? how to i create the window and output/imput text from it?
Posted on 2002-04-26 19:19:08 by Qages
in the examples directory of masm32 you'll find an example of what you need. It's called TextIO and is found in \masm32\example3
Posted on 2002-04-27 05:17:32 by Hiroshimator
Just remember to link with the /subsystem:console option.

/Flyke
Posted on 2002-04-27 07:50:09 by Flyke
If you use QEditor, instead of Project...Build All click on Project...Console Build All
Posted on 2002-04-27 11:22:27 by Ronin Magus
hi, im trying to make a text command thing, well im im putting 'cls' as text into the console, is there a termanating null at the end of that in the buffer? if there isnt then it might mistake it for another command
Posted on 2002-04-27 19:12:53 by Qages
nevermind about that above, ive gotten away around that, how do i pass paramters to my program? ,like if i ran 'c:\console.exe path.exe' and it will open up and show path.exe
Posted on 2002-04-27 20:23:11 by Qages
i also have a nother problem, i cant seem to clear my buffer of text, it will show rememnetns of the other text imput



; ------------
; Local macros
; ------------
print MACRO Quoted_Text:VARARG
LOCAL Txt
.data
Txt db Quoted_Text,0
.code
invoke StdOut,ADDR Txt
ENDM

input MACRO Quoted_Prompt_Text:VARARG
LOCAL Txt
LOCAL Buffer
.data
Txt db Quoted_Prompt_Text,0
Buffer db 1024 dup(?)
.code
invoke StdOut,ADDR Txt
invoke StdIn,ADDR Buffer,LENGTHOF Buffer
mov eax, offset Buffer
ENDM

cls MACRO
invoke ClearScreen
ENDM

Main PROTO
CRLF equ 13,10
;print "Console function test",13,10,13,10

; #########################################################################

.data
Msg1 db "Type something > ",0
Msg2 db "You typed > ",0
DCLSD db "Screen Cleared.",CRLF
.data?
iBuffer db 128 dup(?)

; #########################################################################

.code

start proc
invoke Main
;invoke ExitProcess,0
ret
start endp

; #########################################################################

Main proc
LOCAL InputBuffer[128]:BYTE
LOCAL ISSCR:DWORD
;first run
mov ISSCR,0
cls
print "Qages Command Shell v1 Alpha",CRLF,"(C) Copyright 1999-2002 Qages Software.",CRLF,CRLF

@STARTJ:
cmp ISSCR,1
je @1
jmp @2
@1:
cls
;screen cleared
print "Qages Command Shell v1 Alpha",CRLF,"(C) Copyright 1999-2002 Qages Software.",CRLF,CRLF
input "Screen Cleared.",CRLF,CRLF,"Command > "
mov ISSCR,0
jmp @3
@2: ; regular
input "Command > "
@3:
; see if were first command
;;;;;;;;;;;;;;;;;;;;;;;;;;;
cmp BYTE PTR [eax], 'c'
je @F
jmp @4
@@:
cmp BYTE PTR [eax+1], 'l'
je @F
jmp @4
@@:
cmp BYTE PTR [eax+2], 's'
je @F
jmp @4
@@:
cmp BYTE PTR [eax+3], 0dh
je @clearscreenj
jmp @4
@clearscreenj: ; execute the command
cls
invoke StdOut, addr DCLSD
mov ISSCR,1
jmp @STARTJ
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@4: ; next command req
cmp BYTE PTR [eax], 'e'
je @F
jmp @5
@@:
cmp BYTE PTR [eax+1], 'x'
je @F
jmp @5
@@:
cmp BYTE PTR [eax+2], 'i'
je @F
jmp @5
@@:
cmp BYTE PTR [eax+3], 't'
je @F
jmp @5
@@:
cmp BYTE PTR [eax+4], 0dh
je @F
jmp @5
@@:
invoke ExitProcess,0
jmp @STARTJ
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@5:
cmp BYTE PTR [eax], 'e'
je @F
jmp @6
@@:
cmp BYTE PTR [eax+1], 'c'
je @F
jmp @6
@@:
cmp BYTE PTR [eax+2], 'h'
je @F
jmp @6
@@:
cmp BYTE PTR [eax+3], 'o'
je @F
jmp @6
@@:
cmp BYTE PTR [eax+4], 20h
je @F
jmp @6
@@:
add eax, 5
invoke StdOut,eax
sub eax, 5

jmp @STARTJ
;;;;;;;;;;;;;;;;;;;;;;;;;

@6:
@7:
@8:
;noting yet, we went thro all return to start
push eax
print "'"
pop eax
push eax
invoke StrLen,eax
mov ebx,eax
pop eax
sub ebx,2
mov DWORD PTR [eax+ebx],0h;isnt the best but ive tryed every thing and thisis how i have it
add ebx,4
mov DWORD PTR [eax+ebx],0h
add ebx,4
mov DWORD PTR [eax+ebx],0h
add ebx,4
mov DWORD PTR [eax+ebx],0h
add ebx,4
mov DWORD PTR [eax+ebx],0h
add ebx,4
mov DWORD PTR [eax+ebx],0h
add ebx,4
mov DWORD PTR [eax+ebx],0h
add ebx,4
mov DWORD PTR [eax+ebx],0h
add ebx,4
mov DWORD PTR [eax+ebx],0h
add ebx,4
mov DWORD PTR [eax+ebx],0h
add ebx,4
mov DWORD PTR [eax+ebx],0h
add ebx,4
mov DWORD PTR [eax+ebx],0h
add ebx,4
mov DWORD PTR [eax+ebx],0h
add ebx,4
mov DWORD PTR [eax+ebx],0h
add ebx,4
mov DWORD PTR [eax+ebx],0h
add ebx,4
mov DWORD PTR [eax+ebx],0h
add ebx,4
mov DWORD PTR [eax+ebx],0h
add ebx,4
mov DWORD PTR [eax+ebx],0h
add ebx,4
mov DWORD PTR [eax+ebx],0h
add ebx,4
mov DWORD PTR [eax+ebx],0h
add ebx,4
mov DWORD PTR [eax+ebx],0h
add ebx,4
mov DWORD PTR [eax+ebx],0h
add ebx,4
mov DWORD PTR [eax+ebx],0h
add ebx,4
mov DWORD PTR [eax+ebx],0h
add ebx,4
mov DWORD PTR [eax+ebx],0h
add ebx,4
mov DWORD PTR [eax+ebx],0h
add ebx,4
mov DWORD PTR [eax+ebx],0h
add ebx,4
mov DWORD PTR [eax+ebx],0h
add ebx,4
mov DWORD PTR [eax+ebx],0h
add ebx,4
mov DWORD PTR [eax+ebx],0h
add ebx,4
mov DWORD PTR [eax+ebx],0h
add ebx,4
mov DWORD PTR [eax+ebx],0h
add ebx,4
mov DWORD PTR [eax+ebx],0h
add ebx,4
mov DWORD PTR [eax+ebx],0h
add ebx,4
mov DWORD PTR [eax+ebx],0h
add ebx,4
mov DWORD PTR [eax+ebx],0h
add ebx,4
mov DWORD PTR [eax+ebx],0h

invoke StdOut,eax
print "'"
print " is not recognized as an internal or external command, operable program or CMD file.",CRLF,CRLF
jmp @STARTJ


ret
Main endp
Posted on 2002-04-27 22:21:46 by Qages
Well there is alot to be said, but in short here is the fix your looking for. You had one problem, and one oversight :)

The problem is that your were declairing a new 1024 buffer everytime you used the macro. And then the buffer is 'left' to retain memory never used again. This is because you were using the LOCAL to make a 'unique' name for the 1024 buffer every time the macro was called.

To fix this, i put a one time condition around it: If not yet defined, define an equate that says you have now a buffer. Then delair the buffer in the .data? segment. The next time the macro is called, the equate will be false, cause the buffer now exists, and it will be reused.

The oversight was that you need to also call StripLF to remove the "enter" key and replace it with a null character, so that the buffer will know where the end is.

With these two things in place, you code needed to be modified to stop checking for the '0D' character (cause its now not in the buffer).

As well, your forgetting that calling anything is 99% likely to change the value of eax. In your echo, you were adding 5 to eax, to adjust the buffer starting point, calling the StdOut, and then sub eax. EAX will change after this call, so i PUSHED/POPPED eax and then did two line returns (since the 0d is now not in the buffer data).

Here you go back.. :)
:alright:
NaN

PS: The way your checking for 'commands' is very cumbersome, and can be done in much more efficent ways. I can give you some help on this if your interested, but i get the feeling this is a learning project so i dont want to 'impose' on what your still learning. :)
Posted on 2002-04-27 23:12:23 by NaN
i would like another way of checkin for commands

ive gotten every thing in working order
id like to learn somtin new or how to do somting in a new way,
also how do i pass paramters to my program from outside
Posted on 2002-04-27 23:22:01 by Qages
Here is a full source framework. Its how i would go about doing what your looking to do. It will parse command lines, as well as handle 'commands'.

I wrote only a few commands to show you. As well, i have a pretty powerful macro that does the 'dirty work' of dealing with text strings. It will enter the string into memory, and then provide a check algo for that string, and jmp to a specified offset if the string is a match. Its not 'optomal' for speed, but you shouldnt notice any lag anyways (since your running in a command window).

The macro is called ON. Its used like so:

ON -VER THEN Do_Version

This will create a string and enter "-VER",0 in the .data section
Then it will add the code lines to compare the 'Buffer' to this string
If they are equal, it will jump to "Do_Version".

If none are valid, it will do the default message (error).

So, in short, to add a new command, simply add another "ON command THEN Do_Command_Handler" and provide a label to jump to.


In the file arguments, i make use of the existing framework, and compar them in the same fashion, except seing that some commandline args might be different from normal commands, they are in a separate handler. I also show how to forward a commandline arg to the normal command handle so that you dont have to re-write the same code into two handlers.

Lastly, i tweeked it by making the commands case insensitive, so EcHo, ecHO, ecHo, etc will all work.

Im pretty happy with this, and will keep it for myself, its a good starting "template", hope you think so to.

PS: When you check it out, test it with this command line :)
Command2.exe -CLS -VER -NaN


:alright:
NaN
Posted on 2002-04-28 03:01:17 by NaN