The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Farabi on July 24, 2005, 04:14:28 AM

Title: Internet function?
Post by: Farabi on July 24, 2005, 04:14:28 AM
I have upload an exe on a website, and I want my program auto download it after promt the auto update to the user, how to do it and what API I must use?
Title: Re: Internet function?
Post by: ctt on July 24, 2005, 07:06:04 AM
Look at this example here (http://spiff.tripnet.se/~iczelion/files/http15.zip).

Good luck!
Title: Re: Internet function?
Post by: Faiseur on July 24, 2005, 11:31:01 AM
You can simplify your work with API UrlDownloadToFile (see in example 12 in Masm package) or using Wininet :


GetWinInetFile PROTO :DWORD,:DWORD


.code

; Success == 1, 0 == error
GetWinInetFile PROC fUrl,fSav:DWORD
LOCAL hUrl,fHand,bwrite,szBuffer,hSession: DWORD
LOCAL Buffer[1024]: BYTE

mov hSession, FUNC (InternetOpen,chr$('toto'),INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,NULL)
.if hSession != 0
    mov hUrl,FUNC (InternetOpenUrl,hSession,fUrl,NULL,NULL,NULL,NULL)
    .if hUrl != 0
        mov fHand, FUNC (CreateFile,fSav,GENERIC_READ or GENERIC_WRITE,FILE_SHARE_READ,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0)
        .if fHand != INVALID_HANDLE_VALUE
            inc szBuffer
            .WHILE szBuffer != 0
               invoke InternetReadFile,hUrl,addr Buffer,sizeof Buffer,addr szBuffer
               invoke WriteFile,fHand,addr Buffer,szBuffer,ADDR bwrite,NULL
            .ENDW
            invoke CloseHandle,fHand
            invoke InternetCloseHandle,hUrl
            invoke InternetCloseHandle,hSession
        .endif         
    .endif
.endif
ret
GetWinInetFile ENDP
Title: Re: Internet function?
Post by: Farabi on July 24, 2005, 03:10:52 PM
Thanks. I will ty it.