News:

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

Console mode in win32

Started by realcr, October 20, 2006, 03:13:09 PM

Previous topic - Next topic

realcr

Hi everyone!

I always write window based assembly code , but today I figured out I have no idea how to use printf on console using masm.
I tried importing the printf function and it didn't work. I know for sure someone probably asked this question before but I couldn't find it myself in this forum.
Can anyone point me to some simple "hello world" program using console mode 32 bit ?

thanks,
bar.


redskull

.486   
.model flat, stdcall
option casemap:none
         
includelib \masm32\lib\kernel32.lib   
include \masm32\include\kernel32.inc

STD_OUTPUT_HANDLE  equ -11
STD_INPUT_HANDLE equ -10

.data?               
hConsoleOutput    DWORD ?
hConsoleInput   DWORD ?      
lpcchWritten   DWORD ?
InputString   DWORD ?
lpcchRead      DWORD ?

.data                  
DisplayString db "Press Enter to exit"

.code                  
start:               

invoke AllocConsole
invoke GetStdHandle, STD_OUTPUT_HANDLE
mov hConsoleOutput, eax
invoke GetStdHandle, STD_INPUT_HANDLE
mov hConsoleInput, eax


invoke WriteConsole, hConsoleOutput, ADDR DisplayString, \
                      SIZEOF DisplayString, ADDR lpcchWritten, \
                      0


invoke ReadConsole, hConsoleInput, ADDR InputString, 1, \
                     ADDR lpcchWritten, 0

invoke ExitProcess, 0
end start
Strange women, lying in ponds, distributing swords, is no basis for a system of government

Vortex

realcr,

Here is an example with printf :

.386
.model flat, stdcall
option casemap :none

include     \masm32\include\kernel32.inc
include     msvcrt.inc

includelib  \masm32\lib\kernel32.lib
includelib  \masm32\lib\msvcrt.lib

.data
message     db 'Hello world!',0

.code

start:

    invoke  printf,ADDR message
    invoke  ExitProcess,0

END start

[attachment deleted by admin]

realcr

Great thanks vortex and redskull!

bar.