News:

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

Console Input-Output

Started by RuiLoureiro, March 18, 2005, 03:32:51 PM

Previous topic - Next topic

RuiLoureiro

Where to get a simple program exemple for leading with console input-output ?

mnemonic

Be kind. Everyone you meet is fighting a hard battle.--Plato
-------
How To Ask Questions The Smart Way

RuiLoureiro


Vortex


.386
.model flat,stdcall
option casemap:none

include     \masm32\include\windows.inc
include     \masm32\include\kernel32.inc
include     \masm32\include\masm32.inc
includelib  \masm32\lib\kernel32.lib
includelib  \masm32\lib\masm32.lib


.data
msg1 db 'Please type your name',13,10,0
msg2 db 'Nice to see you ',0

.data?
buffer db 100 dup(?)
.code

start:
invoke StdOut,ADDR msg1
invoke StdIn,ADDR buffer,100 ; receive text input
invoke StdOut,ADDR msg2
invoke StdOut,ADDR buffer
invoke ExitProcess,0
END start

RuiLoureiro

Hi all and Vortex

Thank you for your help. I go to study this case

Regards

hitchhikr

From the example mentioned above you may want to have a buffer with length of 100+1 initialized to 0 if you want to print it with StdOut() instead.
StdIn() uses ReadFile() which handles the buffer as binary (so it's not padding it with a null terminating 0) and as StdOut() uses StrLen() it may have trouble to return the real length of the buffer if it's directly followed with odd datas from some other buffer or variables or unallocated memory (in that case it may crash).

dsouza123

If you are using the MASM32 Editor
which conviently calls the MASM32 Assembler from a menu
use the following tip/caveat

To assemble a console app use the menu
Project -> Console Assemble & Link

if you just do
Project -> Assemble & Link

it creates a GUI app,
which wont appear to run. :U

Learned this from experiencing it first hand.

RuiLoureiro

Hi
    Ok.
    That code given by Vortex does nothing. The program enter and exit !!!

    Why ? Do you Know ?

Stay well
Regards

mnemonic

Quote from: RuiLoureiro on March 30, 2005, 09:14:54 PMThat code given by Vortex does nothing.
You probably builld it as a window application. You have to build it as a console application.
I just tried it with QEditor. If you use the bat files check that you use the ones with a "c" at the end ("BLDALLC.BAT").
That way it will work.

Regards
Be kind. Everyone you meet is fighting a hard battle.--Plato
-------
How To Ask Questions The Smart Way

MichaelW

Quote from: RuiLoureiro on March 30, 2005, 09:14:54 PM
That code given by Vortex does nothing. The program enter and exit !!!

It works just as it should. If you are using QE, paste the code into QE, save it, assemble and link with the Console Assemble & Link command on the Project menu, press Ctrl+D to open a prompt, and run it.
eschew obfuscation

Vortex

Hi RuiLoureiro,

For your information, I never send untested code snippets to the board. Assemble the source code and link it as console application. Please let me know if you have other questions concerning the example.

RuiLoureiro

Hi all
   
   thank hitchhikr, dsousa123 for your help

   thank mnemonic. Your help was appropriate and well-seen. I used a batch file with link for window application: /SUBSYSTEM:WINDOWS. I deduced it because I have the batch files BUILD.bat, BLDALL.bat, BUILDC.bat and BLDALLC.bat. This last, has LINK ... /SUBSYSTEM:CONSOLE. The problem is documentation. Or better, «good documentation». Those files are in BIN directory which hasn't any readme or info file about each file and its use. Thank you.

Thank MichaelW.

Vortex, «Nice to see you» !

[«For your information, I never send untested code snippets to the board»:
So, Code it... That's all...]

       thank you for your reply. Yes i din't think that that code example
       doesn't work. The problem here is my problem with the windows itself.
       Now, i know console apps are different from windows apps.

-----------------------------------------------------------
It works, but:
1.   Of course, it doesn't let us see «Nice to see you» !
2.   The enter key close the program;
3.   PgUp, Up, Down, etc. clear the work space;
4.   The window is not adjusted to all the screen.
-----------------------------------------------------------
What is the meaning of each of the following LINK options ?

      /EXETYPE:DYNAMIC            ; what is this for ?
      /FIXED[:NO]               ; FIXED:NO ?
      /HEAP:reserve[,commit]            ; what is this for ?
      /INCREMENTAL:{YES|NO}            ; INCREMENTAL:NO ?
      /STACK:reserve[,commit]            ; what is this for ?

Whats the difference between

      /SUBSYSTEM:WINDOWS and   /SUBSYSTEM:WINDOWSCE ?   
Whats WINDOWSCE ?

Stay well
RuiLoureiro

Vortex

Hi RuiLoureiro,

Here is how to build the sample code:

\masm32\bin\ml /c /coff Sample.asm
\masm32\bin\link /SUBSYSTEM:CONSOLE Sample.obj






[attachment deleted by admin]

RuiLoureiro

Hi Vortex,

   Thank you for Sample.zip file.
   Yes, in the command line my Console.exe gives exactly the same as your Sample.exe.
   I understood the example given. In other words, print msg1, input to buffer, print msg2 and next the buffer.
   Today i was studying functions like ReadConsoleInput ReadConsole
WriteConsole, WriteConsoleInput , SetCursorPos , GetCursorPos, SetCursorPos ShowCursor, SetCursor, etc. as well as the procedures ( StdIn, StdOut ) that are in M32Lib folder.
   I don't see any application where to use these 2 functions StdIn and StdOut. I think it is necessary to read each key from keybord and control it. I need to distinguish control keys from others.
   StdOut PROTO :DWORD and StdIn  PROTO :DWORD,:DWORD are in MASM32.INC. The procedures ( StdIn, StdOut ) are defined in M32Lib folder. These procedures are in library MASM32.LIB too, i think ( it must ). So, to build new procedures like StdIn and StdOut, which control the set of  keys we want we need to write two new procedures and put them in, for example, MASM32.inc ( protos ) and MASM32.LIB (procedures). To do this we use LIB, no ? Would you mind to give me an example of how to to this ?
;---------------------------------------------------------------------------------------------------------
stay well
regards
RuiLoureiro

Xor Stance

http://radasm.visualassembler.com/ Well, until looking now up again at Radasm does a great job, for learning would be appropiate to have a fast
compilation in IDE. Below are the tutorials to use Radasm.

http://members.a1.net/ranmasaotome/main.html