EuroAssembler Index Manual Download Source Macros


Sitemap Links Forum Tests Projects

twinapi.htm

This program is designated for demonstration and testing of the base functions from 32-bit Windows Application Programming Interface macrolibrary winapi.htm : WinAPI, GetArgCount, PutArg, PutEnv, StdInput, StdOutput, TerminateProgram.

Format
PE 32-bit
Platform
MS-Windows
Build
euroasm twinapi.htm
Run
twinapi arg1 arg2 ...
See also
tdosapi.htm, twinabi.htm.
        EUROASM CPU=486
twinapi PROGRAM Format=PE,WIDTH=32,Entry=Main:
         INCLUDE winapi.htm, cpuext%^WIDTH.htm
         EUROASM UNICODE=Yes ; or
       ; EUROASM UNICODE=No  ; twinapi can be assembled in any Unicode mode.

          %IF %^UNICODE
%CharMode  %SET WIDE
          %ELSE
%CharMode  %SET ANSI
          %ENDIF
%StdConsole %SETB Yes     ; Set StdOutput Console mode, which displays ANSI and WIDE strings correctly.

Main:    PROC
          StdOutput ="twinapi.exe is demo of macrolibrary winapi.htm assembled in %CharMode mode.",Eol=Yes

; Test GetArg, display count and values of arguments from command line:
          StdOutput Eol=Yes
          StdOutput =B"Testing GetArgCount, GetArg:", Console=No, Unicode=No, Eol=Yes
          GetArgCount     ; Count the command-line arguments.
          JC .Abort:
          MOV [ArgCount],ECX
          MOV EAX,ECX
          StoD ArgCount$  ; Convert binary number EAX to a decimal ANSI string.
          JC .Abort:
          StdOutput Eol=Yes
          StdOutput =B"%^PROGRAM launched with ", ArgCount$, =B" arguments:", Console=No, Unicode=No, Eol=Yes
          JC .Abort:
          SUB EBX,EBX     ; EBX will be the ordinal number of each argument.
.EchoArg: CMP EBX,[ArgCount]
          JA .EchoEnv:    ; Jump when all arguments have been echoed.
          MOV EAX,EBX
          StoD ArgNr$     ; Convert binary number EAX to a decimal ANSI string.
          SUB EAX,EAX
          STOSB           ; Zero-terminate the argument ordinal number.
          GetArg EBX      ; Retrieve EBX-th argument to ESI,ECX.
          JC .Abort:
          MOV EAX,ECX     ; Argument size in bytes.
          StoD ArgSize$   ; Convert binary number EAX to a decimal string.
          SUB EAX,EAX
          STOSB           ; Zero-terminate the argument size.
          StdOutput =B'Argument ',ArgNr$, =B" [", ArgSize$, =B" bytes]: ", Console=No, Unicode=No
          StdOutput ESI, Size=ECX, Eol=Yes ; Echo the argument value.
          JC .Abort:
          INC EBX
          JMP .EchoArg:

; Test PutEnv, display value of three environment variables.
.EchoEnv: StdOutput Eol=Yes
          StdOutput ='Environment strings ',EnvName1,=', ',EnvName2,=', ',EnvName3, Eol=Yes
envNr     %FOR 1,2,3
           StdOutput EnvName%envNr,=" [",
           PutEnv EnvName%envNr,EnvVal%envNr,IgnoreCase=Yes
           MOV EAX,ECX   ; Size of environment variable.
           StoD EnvSize$ ; Convert binary number EAX to a decimal ANSI string.
           SUB EAX,EAX
           STOSB         ; Zero terminate the decimal number.
           StdOutput EnvSize$, Unicode=No
           StdOutput =" bytes]: ",EnvVal%envNr, Eol=Yes
          %ENDFOR envNr

; Test StdInput and StdOutput with four combinations of ANSI/WIDE and File/Console access method:
          StdOutput Eol=Yes
          StdOutput ="Testing StdOutput, StdInput using 4 combination of modes:",Eol=Yes
 unicode  %FOR No,Yes
 console   %FOR No,Yes
            StdOutput ="Input/Output mode: Unicode=%unicode, Console=%console", Eol=Yes
            StdOutput =B"Enter some text: ", Console=No, Unicode=No
            StdInput Buffer, Console=%console, Unicode=%unicode
            JC .Abort:
            MOV EAX,ECX     ; Text size including CR+LF.
            StoD BufSize$   ; Convert binary number EAX to a decimal string.
            SUB EAX,EAX
            STOSB           ; Zero-terminate the string.
            StdOutput =B"Entered [", BufSize$, =B" bytes]: ", Console=No, Unicode=No
            StdOutput Buffer, Size=ECX, Eol=Yes, Console=%console, Unicode=%unicode
            JC .Abort:
           %ENDFOR console
          %ENDFOR unicode

          StdOutput =B"%^PROGRAM terminated.", Console=No, Unicode=No
          TerminateProgram Errorlevel=0
.Abort:   StdOutput =B"Aborted, some macro returned CF.",Eol=Yes,Console=No,Unicode=No
          TerminateProgram Errorlevel=4
         ENDP Main:

EnvName1  D "OS",0
EnvName2  D "Computername",0
EnvName3  D "SystemRoot",0
EnvVal1   D "1111111111111111"
EnvVal2   D "2222222222222222"
EnvVal3   D "3333333333333333"
ArgCount  DD D
ArgCount$ DB 8*B
ArgNr$    DB 8*B
ArgSize$  DB 8*B
EnvSize$  DB 8*B
BufSize$  DB 8*B
Buffer    DB 256*B
      ENDPROGRAM twinapi

▲Back to the top▲