Hi,
if written a little file splitting routine. I parse the
"split size" as a parameter to this function.
My Problem is, how to sub, add or use the "<=" operator
with the parameter. But first look at the source code:
SplitFile proc hParent:DWORD, lpDir:DWORD, lpFile:DWORD, lpSplit:DWORD
invoke CreateFile, lpFile, GENERIC_READ, 0, 0, OPEN_EXISTING, \
FILE_ATTRIBUTE_NORMAL, 0
mov hFile, eax ;// handle der geöffneten datei speichern
invoke GetFileSize, hFile, 0
mov hSize, eax ;// dateigrösse speichern
invoke GlobalAlloc, GHND, eax
mov hMem, eax ;// speicher reservieren
invoke GlobalLock, eax
mov pMem, eax ;// pointer bekommen
invoke ReadFile, hFile, pMem, hSize, addr hRead, 0
.while hSize != 0
inc lpX
invoke wsprintf, addr szOutFile, addr szOutMask, lpDir, lpX
.if hSize <= 1024000
invoke CreateFile, addr szOutFile, GENERIC_WRITE, 0, 0, \
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0
mov hTmp, eax
invoke WriteFile, eax, pMem, hSize, addr hWritten, 0
invoke CloseHandle, hTmp
.break
.endif
invoke CreateFile, addr szOutFile, GENERIC_WRITE, 0, 0, \
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0
mov hTmp, eax
invoke WriteFile, eax, pMem, 1024000, addr hWritten, 0
invoke CloseHandle, hTmp
sub hSize, 1024000
add pMem, 1024000
.endw
invoke GlobalUnlock, pMem
invoke GlobalFree, hMem
invoke CloseHandle, hFile
ret
SplitFile endp
I just want to replace the "1024000" with lpSplit. But this causes
compilation errors on this three lines:
.if hSize <= 1024000
sub hSize, 1024000
add pMem, 1024000
I know, I must convert the lpSplit parameter to a decimal value.
But how?
P.S.: I forgot one thing:
lpSplit must be mul'ed by 1000 before starting the "while loop".
Can this be done with
mov eax, lpSplit ;// already converted to decimal
mov ecx, 1000
mul ecx
mov lpSplitMul, eax
?
This message was edited by bAZiK., on 6/16/2001 3:02:04 PM
This message was edited by bAZiK., on 6/16/2001 3:03:54 PMHi, bAZiK :)
I just want to replace the "1024000" with lpSplit. But this causes
compilation errors on this three lines
You cannot directly compare or add/sub two memory locations. You need to move one of them into a register first:
mov eax,lpSplit
.if hSize <= eax
sub hSize, eax
add pMem, eax
If lpSplit is a pointer to a string, you will have to convert it to a dword value first. Just use the MASM32 library (I bet there's a proc for it) or the following code:
StrToInt PROC USES ebx esi, lpStr: DWORD
mov esi,lpStr
mov ecx,10
xor edx,edx
@StrToIntLoop:
lodsb
test al,al
jz @StrToIntEnd
sub al,'0'
xor ebx,ebx
mov bl,al
lea eax,
lea eax,
lea edx,
dec ecx
jnz @StrToIntLoop
@StrToIntEnd:
mov eax,edx
ret
StrToInt ENDP
Thanx, Tola!
You point me the right direction :)
If anyone is interested, here's my code (perhaps someone can get more speed out of it :D )
EDIT:
Replaced the
mov hTmp, eax
with
push eax
SplitFile proc hParent:DWORD, lpDir:DWORD, lpFile:DWORD, lpSplit:DWORD
invoke CreateFile, lpFile, GENERIC_READ, 0, 0, OPEN_EXISTING, \
FILE_ATTRIBUTE_NORMAL, 0
mov hFile, eax ;// handle der geöffneten datei speichern
invoke GetFileSize, hFile, 0
mov hSize, eax ;// dateigrösse speichern
invoke GlobalAlloc, GHND, eax
mov hMem, eax ;// speicher reservieren
invoke GlobalLock, eax
mov pMem, eax ;// pointer bekommen
invoke ReadFile, hFile, pMem, hSize, addr hRead, 0
;// datei in speicher lesen
invoke atodw, lpSplit ;// ascii to dword
mov ecx, 1000
mul ecx ;// eax * ecx
mov lpSize, eax
.while hSize != 0
inc lpX ;// counter erhöhen
invoke wsprintf, addr szOutFile, addr szOutMask, lpDir, lpX
;// dateinamen erzeugen
mov eax, lpSize
.if hSize <= eax ;// wenn wir am ende der datei sind ...
invoke CreateFile, addr szOutFile, GENERIC_WRITE, 0, 0, \
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0
push eax
invoke WriteFile, eax, pMem, hSize, addr hWritten, 0
;// ... schreiben wir den rest rein
pop eax
invoke CloseHandle, eax
.break
.endif
invoke CreateFile, addr szOutFile, GENERIC_WRITE, 0, 0, \
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0
push eax
invoke WriteFile, eax, pMem, lpSize, addr hWritten, 0
pop eax
invoke CloseHandle, eax
mov eax, lpSize
sub hSize, eax ;// size verkleinern
add pMem, eax ;// pointer verschieben
.endw
invoke GlobalUnlock, pMem ;// speicher freigeben
invoke GlobalFree, hMem
invoke CloseHandle, hFile
ret
SplitFile endp
This message was edited by bAZiK., on 6/17/2001 5:58:26 AM