What's wrong with my COMPARE code?(It's always display the error message!)
Is there a optimized one to compare two files just like the compare function of WinHex?


_COMPARE proc uses esi edi ecx
local @hFile1,@dwBytesRead1
local @hFile2,@dwBytesRead2
local @szBuffer1,@szBuffer2

invoke CreateFile,addr szFileName1,GENERIC_READ,FILE_SHARE_READ,0,\
OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0
.if eax == INVALID_HANDLE_VALUE
invoke MessageBox,hWinMain,addr szErrOpenFile,NULL,MB_OK or MB_ICONEXCLAMATION
ret
.endif
mov @hFile1,eax
invoke CreateFile,addr szFileName2,GENERIC_READ,FILE_SHARE_READ,0,\
OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0
.if eax == INVALID_HANDLE_VALUE
invoke MessageBox,hWinMain,addr szErrOpenFile,NULL,MB_OK or MB_ICONEXCLAMATION
ret
.endif
mov @hFile2,eax

lea esi, @szBuffer1
lea edi, @szBuffer2
invoke ReadFile,@hFile1,addr szBuffer1,sizeof szBuffer1,addr @dwBytesRead1,0
invoke ReadFile,@hFile2,addr szBuffer2,sizeof szBuffer2,addr @dwBytesRead2,0
.while  (@dwBytesRead1 && @dwBytesRead2)
xor eax,eax
mov ecx,eax
mov eax,
mov ecx,
.if eax == ecx
inc esi
inc edi
dec @dwBytesRead1
dec @dwBytesRead2
.else
(invoke MessageBox to display error)
ret
.endif
.endw
(invoke MessageBox to display OK)
                invoke CloseHandle,@hFile1
invoke CloseHandle,@hFile2
ret
_COMPARE endp
Posted on 2005-11-03 00:16:53 by Eric4ever
Isn't it supposed to do that if the files are different?

PS: How big is your buffer?
Posted on 2005-11-03 00:58:27 by roticv
Why not using the file mapping object? When both of the files are mapped into memory, we can compare them directly using instructions that compare strings,as if we compare strings in the memory.
Posted on 2005-11-04 13:27:25 by Cloud

Why not using the file mapping object? When both of the files are mapped into memory, we can compare them directly using instructions that compare strings,as if we compare strings in the memory.

You'll still have to process in chunks (unmap+remap views), otherwise you'll be limited to comparing relatively small files. Also, memory mapping has somewhat more CPU overhead then a FileRead based approach (obviously you're I/O bound so running time will be the same - CPU usage will be higher with mmap though).
Posted on 2005-11-04 16:59:34 by f0dder