Hi, I need your help....
I use a procedure (GetInetFile proc) and I call it with (invoke GetInetFile), the problem mnemonic "ret" did not return to the calling procedure ...Why.... I don't know what is wrong..
Fernand
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
.486 ; create 32 bit code
.model flat, stdcall ; 32 bit memory model
option casemap :none ; case sensitive
include \masm32\include\windows.inc
include \masm32\include\masm32.inc
include \masm32\include\gdi32.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\Comctl32.inc
include \masm32\include\comdlg32.inc
include \masm32\include\shell32.inc
include \masm32\include\oleaut32.inc
include \masm32\include\msvcrt.inc
includelib \masm32\lib\masm32.lib
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\Comctl32.lib
includelib \masm32\lib\comdlg32.lib
includelib \masm32\lib\shell32.lib
includelib \masm32\lib\oleaut32.lib
includelib \masm32\lib\msvcrt.lib
include \MASM32\INCLUDE\wininet.inc
includelib \MASM32\LIB\wininet.lib
.data
fileUrl db "http://delphi.about.com/library/forminbpl.zip",0
fileSave db "saved.zip",0
msgOk db "Downloaded Success!",0
msgErr db "Download Failed!",0
mcap db "Result",0
.data?
; hInstance HINSTANCE ?
AppName db 127 dup(?)
fHand dd ?
bwrite dd ?
.code
start:
GetInetFile proc
LOCAL Buffer[1024]: BYTE
LOCAL hSession: DWORD
LOCAL hUrl: DWORD
LOCAL Bufferlen: DWORD
invoke GetModuleFileName, NULL, addr AppName, sizeof fileUrl
invoke InternetOpen, addr AppName, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, NULL
mov hSession, eax
.if hSession == INVALID_HANDLE_VALUE
mov eax, FALSE
ret
.endif
invoke InternetOpenUrl, hSession, addr fileUrl, NULL, NULL, NULL, NULL
mov hUrl, eax
.if hUrl == INVALID_HANDLE_VALUE
mov eax, FALSE
ret
.endif
invoke CreateFile, addr fileSave, GENERIC_READ or GENERIC_WRITE, FILE_SHARE_READ,\
NULL,CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,NULL
mov fHand, eax
.if fHand == INVALID_HANDLE_VALUE
mov eax, FALSE
ret
.endif
invoke SetFilePointer, fHand, NULL, NULL, FILE_BEGIN
download:
invoke InternetReadFile, hUrl, addr Buffer, sizeof Buffer, addr Bufferlen
.if Bufferlen != 0
invoke WriteFile, fHand, addr Buffer, Bufferlen, ADDR bwrite, NULL
jmp download
.endif
invoke CloseHandle, fHand
invoke InternetCloseHandle, hUrl
invoke InternetCloseHandle, hSession
mov eax, TRUE
ret
GetInetFile endp
; Call this like...
invoke GetInetFile
.if eax == TRUE
invoke MessageBox, NULL, addr msgOk, addr mcap, MB_OK
.else
invoke MessageBox, NULL, addr msgErr, addr mcap, MB_OK
.endif
invoke ExitProcess,NULL
end start
I added the code tags so it could be read more easily.
Fernand,
The "start" label is your program entry point, so your procedure "GetInetFile" must be at the end of your program, otherwise you have to specify the entry point yourself. Also, you must define the prototype of GetInetFile if you want to use INVOKE (or use CALL if you don't want to).
...
GetInetFile PROTO
.data
fileUrl db "http://delphi.about.com/library/forminbpl.zip",0
fileSave db "saved.zip",0
msgOk db "Downloaded Success!",0
msgErr db "Download Failed!",0
mcap db "Result",0
.data?
; hInstance HINSTANCE ?
AppName db 127 dup(?)
fHand dd ?
bwrite dd ?
.code
start:
; Call this like...
invoke GetInetFile
.if eax == TRUE
invoke MessageBox, NULL, addr msgOk, addr mcap, MB_OK
.else
invoke MessageBox, NULL, addr msgErr, addr mcap, MB_OK
.endif
invoke ExitProcess,NULL
GetInetFile proc
...
GetInetFile endp
end start
Thank jdoe,
I appreciate your help, but I have an other question.
Why I have to define the prototype of GetInetFile. The program works ok.....if I did not define it.
Fernand
Quote from: Fernand on September 25, 2007, 10:59:30 PM
Why I have to define the prototype of GetInetFile. The program works ok.....if I did not define it.
Fernand,
Do the modifications that I posted previously without the GetInetFile prototype and you will have the following assembler error message and the program won't be assembled at all.
error A2006: undefined symbol : GetInetFile
INVOKE needs those prototypes for verifying the procedures parameters.
Hi jdoe,
Thanks for your reply. I am learning and I try many things...
I am using Masm32 I removed the prototype, I saved it and I recompiled it and I got no error....?
I'll define the prototype now...
Fernand
Quote from: Fernand on September 26, 2007, 12:52:04 AM
I am using Masm32 I removed the prototype, I saved it and I recompiled it and I got no error....?
Impossible. If you get no error doing so, it means that your program still isn't working.
Post your code and the the command-line you use for ML.EXE
You only need to prototype your own procs if it's a forward reference.
start: call GetInetFile
invoke ExitProcess,0
GetInetFile proc
...
GetInetFile endp
The above code will give you the "undefined symbol" error because GetInetFile is defined after you invoke it.
GetInetFile proc
...
GetInetFile endp
start: call GetInetFile
invoke ExitProcess,0
This code works fine since GetInetFile is defined before you invoke it.
By prototyping it you basically define it before you call it, since PROTOs are usually put before any code.
Hi jdoe, When I compile I use this routine: &Build All,\MASM32\BIN\Bldall.bat {b}
in the [&Project]
@echo off
if not exist rsrc.rc goto over1
\masm32\bin\rc /v rsrc.rc
\masm32\bin\cvtres /machine:ix86 rsrc.res
:over1
if exist "%1.obj" del "%1.obj"
if exist "%1.exe" del "%1.exe"
\masm32\bin\ml /c /coff "%1.asm"
if errorlevel 1 goto errasm
if not exist rsrc.obj goto nores
\masm32\bin\Link /SUBSYSTEM:WINDOWS /OPT:NOREF "%1.obj" rsrc.obj
if errorlevel 1 goto errlink
dir "%1.*"
goto TheEnd
:nores
\masm32\bin\Link /SUBSYSTEM:WINDOWS /OPT:NOREF "%1.obj"
if errorlevel 1 goto errlink
dir "%1.*"
goto TheEnd
:errlink
echo _
echo Link error
goto TheEnd
:errasm
echo _
echo Assembly Error
goto TheEnd
:TheEnd
pause
Fernand
Fernand,
There are few ways to make it work but the way I showed you in my first post need that prototype. Sinsi post a way to avoid prototypes if you don't want to wrote them (moves the start label after your proc).
Post your code if it still don't work.