.386
.model flat, stdcall
option casemap:none
include windows.inc
include kernel32.inc
include user32.inc
includelib user32.lib
includelib kernel32.lib
Main proto
.data
hOutput dd 0
bReadWritten dd 0
szText1 db "What's your name?",0
hInput dd 0
szInput db 128 dup(0)
.data?
.code
start:
Invoke Main
Invoke ExitProcess,0
Main proc
invoke GetStdHandle, STD_OUTPUT_HANDLE
mov hOutput, eax
invoke GetStdHandle,STD_INPUT_HANDLE
mov hInput, eax
invoke lstrlen, addr szText1
invoke WriteFile, hOutput, addr szText1, eax, ADDR bReadWritten, NULL
invoke ReadFile, hInput, addr szInput, 128, ADDR bReadWritten,0
ret
Main endp
end start
Nothing happened after executing this program. Why the console window didn’t appear?
Postscriptum
Assemble options(winAsm):
/Zi /Zd /c /coff /Cp /nologo
Linker options
/SUBSYSTEM:WINDOWS /DEBUG /DEBUGTYPE:CV /VERSION:4.0 /INCREMENTAL:NO
Now it is answerable. That’s the wrong option, that declares that the program is a native Windows program. Which takes care of creating its own windows, using the CreateWindow() api function. Which you can certainly call from an assembly program as well, just not commonly done. You’d at least use a C compiler to go through the rigamarole of creating a window class and properly writing the window procedure. Like Petzold showed us in his seminal “Programming Windows” book.
If you want Windows to create a console window for you then you have to ask for it: