
; extended Win32 programming headers (ASCII)

addr equ
ADDR equ
invoke equ

include 'win32a.inc'

include 'macro/if.inc'

macro allow_nesting
{ macro pushd arg
  \{
     if arg eq
     else if  _ \# arg	eq _invoke arg
      arg
     else
      pushd arg
     end if \}
  macro invoke proc,[arg]
  \{ \common allow_nesting
     \reverse pushd <arg>
     \common call [proc]
	     push eax
	     purge pushd
	     purge invoke \} }

macro pushd first,[more]
{ common local ..continue,..opcode,..address
  if ~ more eq
   call ..continue
   db first,more,0
   ..continue:
  else if _ # first in <_addr first,_ADDR first>
   virtual at 0
    label ..address at first
    mov eax,dword [..address]
    load ..opcode from 0
   end virtual
   if ..opcode = 0A1h
    push first
   else
    lea edx,[..address]
    push edx
   end if
  else if first eqtype ''
   call ..continue
   db first,0
   ..continue:
  else
   push first
  end if }

allow_nesting

macro invoke proc,[arg]
{ reverse pushd <arg>
  common call [proc] }

macro import lib,[functions]
 { common macro import_#lib \{ import lib,functions \} }

include 'apia/kernel32.inc'
include 'apia/user32.inc'
include 'apia/gdi32.inc'
include 'apia/advapi32.inc'
include 'apia/comctl32.inc'
include 'apia/comdlg32.inc'
include 'apia/shell32.inc'
include 'apia/wsock32.inc'

purge import

macro .data { section '.data' data readable writeable }

macro .code { section '.text' code readable executable }

macro .end label
 {
   entry label

   section '.idata' import data readable writeable

     library kernel32,'KERNEL32.DLL',\
	     user32,'USER32.DLL',\
	     gdi32,'GDI32.DLL',\
	     advapi32,'ADVAPI32.DLL',\
	     comctl32,'COMCTL32.DLL',\
	     comdlg32,'COMDLG32.DLL',\
	     shell32,'SHELL32.DLL',\
	     wsock32,'WSOCK32.DLL'

     import_kernel32
     import_user32
     import_gdi32
     import_advapi32
     import_comctl32
     import_comdlg32
     import_shell32
     import_wsock32
 }

virtual at 0
 xchg eax,eax
 detected_16bit = $-1
end virtual

if detected_16bit
 format PE GUI 4.0
end if
