WinInc CUI Sample 1

1. About

"Hello world" sample with WinInc. This is a Win32 console application and uses the Win32 WriteConsole() API to display the text.

2. ScreenShot

in case you don't believe me

3. Source Code

WINCUI1.ASM
;--- the simplest Win32 hello world console application

	.386
	.model FLAT, stdcall
	option casemap:none

ifndef __POASM__
	.nolist
	.nocref
endif
WIN32_LEAN_AND_MEAN equ 1
	include windows.inc
ifndef __POASM__
	.list
	.cref
endif

;--- CStr(): macro function to simplify defining a string

CStr macro pszText:VARARG
local szText
	.const
szText	db pszText,0
	.code
	exitm <offset szText>
endm

	.code

main    proc c uses ebx

	invoke GetStdHandle,STD_OUTPUT_HANDLE
	mov ebx,eax
	mov esi, CStr("Hello, world",13,10)
	invoke lstrlen, esi
	push 0
	mov ecx, esp
	invoke WriteConsoleA, ebx, esi, eax, ecx, 0
	pop eax
	ret

main    endp

mainCRTStartup  proc stdcall
	call main
	invoke ExitProcess,eax
mainCRTStartup endp

	end mainCRTStartup

 

4. Explanations

ifndef __POASM__
        .nolist
        .nocref
endif
This is a PoASM issue, nothing WinInc specific. This assembler does not understand some of MASM's reserved words and will flag them as errors. By using the predefined equate __POASM__ one might avoid those catches.
 
WIN32_LEAN_AND_MEAN equ 1
        include windows.inc
WinInc will understand all declarations contained in the MS Platform SDK. Setting WIN32_LEAN_AND_MEAN to 1 will avoid to include the full Win32 header set, thus increasing assembly speed.
 
The rest of the code does not contain anything specific to WinInc. What's missing compared to MASM32 are things like
        include \masm32\include\kernel32.inc
        include \masm32\include\user32.inc
because in WinInc the function prototypes are not located in separate files.