Continuing my previos topic:
Quoteinvoke CreateFile,ADDR dfile,GENERIC_READ,\
0,0,OPEN_EXISTING,FILE_ATTRIBUTE_ARCHIVE,0
mov hFile,eax
invoke GetFileSize,eax,0
inc eax
mov memsize,eax
invoke GlobalAlloc,GPTR,eax
mov hMem,eax
invoke ReadFile,hFile,eax,memsize,ADDR size1,0
invoke CloseHandle,hFile
mov edx,hMem
@@:
cmp byte ptr [edx],13
jz @f
inc edx
jmp @b
@@:
mov byte ptr [edx],0
invoke szCmp,hMem,ADDR string
or eax,eax
jz @f
invoke MessageBox,0,ADDR dfile,ADDR dfile,MB_OK
@@:
invoke GlobalFree,hMemQuote
When the string in the file is incorrect, then nothing happens, but when the string is correct, then the program crashes... why?
Hi tuto,
There is no any problem with the original code, it loads a text file named test.txt. The first string of the text file is compared to another string containing the word box If both are equal then a message box is displayed.
How it happens that the example code is crashing? ::)
Here is the example code, please check the attachment.
[attachment deleted by admin]
Well the thing is your code worked as long as I didn't change it, once I put it in my code *bam*, the program crashes... :(
The same is with your code, but now I understand why this is: if there is only one line in the file e.g. only "box" then the prog crashes, but if there is "box[newline]something" then it works, why do there have to be two lines? Oh and could the code be done using .IF .ENDIF statements, it would make understanding the code a whole lot easier...
Hi tuto,
The example code will work also with the text file test.txt containing only one line. The code will crash if the line doesn't terminate with CR+LF ( ASCII 13 and ASCII 10 )
C:\masm32\bin>debug test.txt
-d
0C9F:0100 62 6F 78 0D 0A box..
Test.txt should be terminated with a CR+LF. The original txt file has two lines for demonstration purpose, it has nothing special.
Ok thank you, now a bit different problem, here is the source:
Quote.386
.model flat, stdcall
option casemap:none
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib
include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib
include \masm32\include\windows.inc
include \masm32\include\advapi32.inc
includelib \masm32\lib\advapi32.lib
include \masm32\include\urlmon.inc
includelib \masm32\lib\urlmon.lib
include \masm32\include\masm32.inc
includelib \masm32\lib\masm32.lib
.data
url db "http://blabla.net/msdns.txt",0
dfile db "/msdns.txt",0
.data?
filetmp dd ?
readdata dd ?
hFile HANDLE ?
SizeReadWrite DWORD ?
hMemory HANDLE ?
size1 dd ?
hMem dd ?
memsize dd ?
pMemory DWORD ?
.code
_main:
invoke URLDownloadToFile,0,offset url,offset dfile,0,0
invoke ExitProcess, 0 ;exit program
end _main
Why doesn't it download the file? If I use an existing file
Hi tuto,
Downloading files is a completely different topic.
You should check Iczelion's HTTP Downloader for a complete example :
http://spiff.tripnet.se/~iczelion/files/http15.zip
Oh my god... :eek Is there really no easier way (e.g. macro's or something) to acomplish this task? Please...
Sincerely Edgars
Hai. Dont forgot too many using macro can made your program bigger even a bit faster. Macro is not use call and ret thats why it faster than invoke or call.
This works fine.
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
comment * -----------------------------------------------------
Build this template with
"CONSOLE ASSEMBLE AND LINK"
----------------------------------------------------- *
include \masm32\include\urlmon.inc
includelib \masm32\lib\urlmon.lib
.code
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
call main
exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
main proc
fn URLDownloadToFile,0,"http://www.website.masmforum.com/files/random.zip","random.zip",0,0
ret
main endp
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start
Hello,
Where is include \masm32\include\masm32rt.inc ??????????????
It's not in masm32 V8,it's not in SP2 ?????????????????
ToutEnMasm
Will be in the fixed service pack soon.
[attachment deleted by admin]
Hello again,
Thanks,msvcrt.lib and .inc aren't in masm but aren't needed
ToutEnMasm
Hi Hutch,
Thanks for the urlmon library example, I didn't knew about that library.