14.1 WINDOWS API - 3


ReadFile .

BOOL ReadFile(

HANDLE hFile, //

LPVOID lpBuffer, //

DWORD nNumberOfBytesToRead, //

LPDWORD lpNumberOfBytesRead, //

LPOVERLAPPED lpOverlapped //

);

True, 0, .

BOOL WriteFile(

HANDLE hFile, //

LPCVOID lpBuffer, //

DWORD nNumberOfBytesToWrite, //

LPDWORD lpNumberOfBytesWritten, //

LPOVERLAPPED lpOverlapped //

);

1. .

Ideal

p586

model flat

extrn ExitProcess:proc

extrn CreateFileA:proc

extrn CloseHandle:proc

extrn ReadFile:proc

extrn WriteFile:proc

extrn CloseHandle:proc

extrn MessageBoxA:proc

include "win.inc"

dataseg

my db ' - 25', 0

val dd ?

d1 dd ?

d2 dd ?

n1 db 'a.txt', 0

n2 db 'b.txt', 0

msg db 'Error', 0

s1 dd ?

codeseg

begin:

push 0 0 CREATE_ALWAYS 0 0

push GENERIC_WRITE

push offset n1

call CreateFileA

cmp eax, INVALID_HANDLE_VALUE

jne short m1

push MB_OK offset msg offset n1 0

call MessageBoxA

jmp short m2

m1:

mov [d1], eax

mov eax, 0

for1:

mov bl, [my+eax]

test bl, bl

je short break

inc eax

jmp for1

break:

push 0 offset s1 eax offset my [d1]

call WriteFile

test eax, eax

jne short m4

push MB_OK offset msg offset n1 0