flat assembler
Message board for the users of flat assembler.

Index > Windows > WIN32 Console Tutorial

Author
Thread Post new topic Reply to topic
calpol2004



Joined: 16 Dec 2004
Posts: 110
calpol2004
I'm having trouble trying to find a tutorial on creating WIN32 console programs, I have just about got the hang of making DOS programs and creating simple WIN API programs, and would like to try something new. Any help appreciated.

cal
Post 22 Feb 2005, 18:15
View user's profile Send private message MSN Messenger Reply with quote
gumletis



Joined: 18 Dec 2004
Posts: 128
gumletis
i also wanna do that, but don't even know how to get input, or output, i know how to make the console, do like this

1. Open your included folder, and copy "win32ax.inc" to "win32console.inc"
2.. Edit the first thing "format PE 4.0" to "format PE console" in the file "win32console.inc"
3. your ready!


example on how to do it with the console

include '%fasminc%\win32console.inc'
.data
hello db 'hello world',0
.code
start:
invoke MessageBox,0,hello,hello,MB_OK
invoke ExitProcess,0
.end start
Post 22 Feb 2005, 18:57
View user's profile Send private message Reply with quote
Nikolay Petrov



Joined: 22 Apr 2004
Posts: 101
Location: Bulgaria
Nikolay Petrov
if you want to work with console - use crtdll.dll or msvcrt.dll(C runtime libraries). You will find many help about it in the net and not only
look at this is example as begining.
Code:
;fasmw 1.57 console program
format PE CONSOLE
entry start
include '%fasminc%\win32a.inc'
;«««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
section "ComSpec" code readable executable

start:
     invoke     SetConsoleTitle,AppTitle
     cinvoke    __GetMainArgs,argc,argv,env_arr,0
     ;show num arguments
     cinvoke    printf,szArgc,[argc]
     ;show arguments
     xor        ecx,ecx
     mov        eax,[argv]
@@:
     cmp        dword[eax+4*ecx],0
     je         @f
     push       eax ecx
     lea        edx,dword[ecx+1]
     cinvoke    printf,szArgv,edx,dword[eax+4*ecx]
     pop        ecx eax
     inc        ecx
     jmp        @r
@@:
     ;show  array environment variables
     cinvoke    printf,EnvText
     xor        ecx,ecx
     mov        eax,[env_arr]
@@:
     cmp        dword[eax+4*ecx],0
     je         @f
     push       eax ecx
     lea        edx,dword[ecx+1]
     cinvoke    printf,szEnv,edx,dword[eax+4*ecx]
     pop        ecx eax
     inc        ecx
     jmp        @r
@@:
     cinvoke printf,entexit
     cinvoke getchar
     cinvoke exit,0
;«««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
section ".data" data readable writeable
;«««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
n equ 13,10 ;enter
t equ 9     ;tab
 AppTitle db " Command Line Demo",0
 entexit  db n,n,"Press Enter to exit...",0
 szArgc    db "Command Line Argumets = %d",n,n,0
 szArgv    db "Argument %d - %s",n,0
 szEnv     db "%d - %s",n,0
 EnvText   db n,n,"Environment Variables:",n,n,0
 argv     dd ? ;arguments
 argc     dd ? ;num arguments
 env_arr  dd ? ;array environment variables
;«««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
section ".idata" import data readable

  library kernel32, "kernel32.dll",\
          crtdll,   "crtdll.dll"

  import kernel32,SetConsoleTitle,'SetConsoleTitleA'

  import crtdll,\
         __GetMainArgs, '__GetMainArgs',\
         getchar,       'getchar',\
         exit,          'exit',\
         printf,        'printf'
;«««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
;.rdata ; --> if you want to add version or icon    
Post 22 Feb 2005, 20:20
View user's profile Send private message Reply with quote
iklin



Joined: 20 Mar 2004
Posts: 120
Location: Russia, Siberia
iklin
This is my little template code for console proggies. Smile
Code:
format PE console
entry start

Include '%fasminc%\win32a.inc'
Include '%fasminc%\fresh\globals.inc'

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; macro section

struc dc [data] {
common
  .data db data,0
  .size = $-.data-1
}

macro write str {
   invoke  WriteFile, [hout], str, str#.size, temp, 0
; invoke  WriteConsole, [hout], str, str#.size, temp, 0
}

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; initialized data
iglobal
  _hello       dc 13,10,'Hello, world!',13,10
endg

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; uninitialized data
uglobal
  hinstance           dd ?
;  hheap                dd ?
  hout          dd ?
  temp          dd ?
endg

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; code section
;section '.code' code readable executable
start:
        invoke  GetModuleHandle, 0
  mov     [hinstance], eax
;   invoke  GetProcessHeap
;     mov     [hheap], eax
        invoke  GetStdHandle, STD_OUTPUT_HANDLE
     mov     [hout], eax

     write   _hello

finish:
   invoke  ExitProcess, 0

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; import section
;section '.idata' import data readable writeable
  library kernel32,'kernel32.dll'

  import kernel32,\
         ExitProcess,'ExitProcess',\
         GetModuleHandle,'GetModuleHandleA',\
         GetProcessHeap,'GetProcessHeap',\
         GetStdHandle,'GetStdHandle',\
         WriteFile,'WriteFile'

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; data section
;section '.data' data readable writeable
IncludeAllGlobals
    
Post 23 Feb 2005, 17:47
View user's profile Send private message ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.