The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: tuto on May 28, 2005, 02:51:26 PM

Title: Problem with a code
Post by: tuto on May 28, 2005, 02:51:26 PM
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,hMem
Quote
When the string in the file is incorrect, then nothing happens, but when the string is correct, then the program crashes... why?
Title: Re: Problem with a code
Post by: Vortex on May 28, 2005, 03:13:12 PM
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]
Title: Re: Problem with a code
Post by: tuto on May 28, 2005, 03:38:27 PM
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...   :(
Title: Re: Problem with a code
Post by: tuto on May 28, 2005, 03:42:00 PM
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...
Title: Re: Problem with a code
Post by: Vortex on May 28, 2005, 04:28:20 PM
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.
Title: Re: Problem with a code
Post by: tuto on May 28, 2005, 04:29:59 PM
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
Title: Re: Problem with a code
Post by: Vortex on May 28, 2005, 04:38:06 PM
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
Title: Re: Problem with a code
Post by: tuto on May 28, 2005, 07:48:05 PM
Oh my god...  :eek Is there really no easier way (e.g. macro's or something) to acomplish this task? Please...

Sincerely Edgars
Title: Re: Problem with a code
Post by: Farabi on May 30, 2005, 12:08:49 PM
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.
Title: Re: Problem with a code
Post by: hutch-- on May 30, 2005, 12:22:32 PM
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
Title: Re: Problem with a code,a little question
Post by: ToutEnMasm on May 30, 2005, 01:34:15 PM
Hello,
Where is include \masm32\include\masm32rt.inc        ??????????????
It's not in masm32 V8,it's not in SP2          ?????????????????
                                  ToutEnMasm

Title: Re: Problem with a code
Post by: hutch-- on May 30, 2005, 02:12:27 PM
Will be in the fixed service pack soon.

[attachment deleted by admin]
Title: Re: Problem with a code
Post by: ToutEnMasm on May 30, 2005, 03:19:25 PM
Hello again,
Thanks,msvcrt.lib and .inc aren't in masm but aren't needed
                       ToutEnMasm

Title: Re: Problem with a code
Post by: Vortex on May 30, 2005, 05:10:23 PM
Hi Hutch,

Thanks for the urlmon library example, I didn't knew about that library.