Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Function : InternetFileRead() aka UrlDownLoadToVar()


  • Please log in to reply
161 replies to this topic
SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

Note that there are numerous (similar) alternatives to the Global memory management functions such as the Heap, Virtual, Local or C run-time functions. See Memory Management Functions and malloc/free.


.. another important function which is actually my recommendation: CoTaskMem.... Although it's not mentioned explicitly in the page, I think it's thread-safe which is not that important with current AHK though.
<!-- m -->http://msdn.microsof...y/aa366533.aspx<!-- m -->


Thank you both for the info and links :)

tank
  • Administrators
  • 4345 posts
  • AutoHotkey Foundation
  • Last active: Feb 04 2019 09:54 PM
  • Joined: 21 Dec 2007

You may force download the file if you can guesstimate the file size:

and what if you just say plug in a over estamated size?
Never lose.
WIN or LEARN.

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

and what if you just say plug in a over estamated size?


The function will set ahk errorlevel to 1 if you had guessed a smaller size for the file. I wanted to say that "you can use the errorlevel to guess estimate the file size by calling it again with increased file size."

This way, it would result in more resource usage, but can be helpful if the file size range is very wide.

Drugwash
  • Members
  • 1078 posts
  • Last active: May 24 2016 04:20 PM
  • Joined: 07 Sep 2008
Dunno if I'm way out of track here but I just remembered the recording test offered with the BASS library, which keeps enlarging a memory buffer while recording audio. It's using malloc/realloc which is compatible with Win9x and working OK here; I'm wondering if the same principle could be used here, to download a file without having to know its size beforehand.
I've seen lots of downloads (usualy Yahoo Mail ones) where the IE dialog says "size unknown" and keeps downloading until EOF or something breaks the download.

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

download a file without having to know its size beforehand.


Allow me some time, friend. I will definitely look into it. :)

Drugwash
  • Members
  • 1078 posts
  • Last active: May 24 2016 04:20 PM
  • Joined: 07 Sep 2008
Sure thing, not pushing or anything - just trying to help with some ideas. :oops:

Elesar
  • Members
  • 696 posts
  • Last active: May 08 2015 09:51 PM
  • Joined: 28 Jun 2007
I am having some difficulty in using this function from work.

I have tried the examples provided from home and they work fine, but when connected from work (via Proxy) the script crashes AHK (Not just times out, pops the windows non-responsive program dialog, killing all of my running scripts).

I am attempting to use this in a couple of new scripts that I am writing, but I cannot find a format that will allow this function to work over Proxy.

I can use URLDownloadToFile just fine, along with this function that you made a while back.

I have tried adding in a MsgBox to display the ErrorLevel, but when the script doesn't crash, it displays ErrorLevel as 0, but my variable is still blank.

I have also ensured that I am running the latest version of AHK, as I just reinstalled it before this posting.

Also of note, the one time that the provided examples did not crash, the first two did nothing, but the FTP transfer worked ok, but did not have the DLP displayed, but the installer popped after I waited a little while.

Could you provide an example of use with Proxy connections, or some insight as to what may be going wrong here?

EDIT:
Home system - Windows Vista Ult. x64 - Scripts work fine.
Work system - Windows XP Pro - Scripts crash AHK.

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

Work system - Windows XP Pro - Scripts crash AHK.


:(

Unfortunately, I do not have access to a proxy server setup and so I cannot test this. I have just adapted that part of code from Olfen's HttpQueryInfo().
If you can provide more info and can run a few tests, we may solve this by trial & error.

The following is the offending line:
; Line #5 of InternetFileRead()
If ! hIO:=DllCall( LIB "InternetOpenA", Str,N, UInt,[color=red]Prx ? 3:1[/color], Str,Prx, Str,PBP, UInt,0 )    Return -1 

/*
INTERNET_OPEN_TYPE_PRECONFIG = 0
INTERNET_OPEN_TYPE_DIRECT    = 1
INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY = 4
INTERNET_OPEN_TYPE_PROXY = 3
*/

Try changing Prx ? 3:1 with 0 and call the function without passing Prx & PBP parameters.
Try changing Prx ? 3:1 with 4 and call the function without passing Prx & PBP parameters.

Also, please run the following code, and if you can, let me know the result:

RegRead, ProxyEnable, HKEY_CURRENT_USER,Software\Microsoft\Windows\CurrentVersion\Internet Settings, ProxyEnable
RegRead, ProxyServer, HKEY_CURRENT_USER,Software\Microsoft\Windows\CurrentVersion\Internet Settings, ProxyServer
RegRead, ProxyOverride, HKEY_CURRENT_USER,Software\Microsoft\Windows\CurrentVersion\Internet Settings, ProxyOverride
Clipboard :=  "Proxy Enabled`t: " ( ProxyEnable ? "True":"False" ) "`nProxy Server`t: " ProxyServer "`nProxy Override`t: " ProxyOverride
MsgBox,0, 64, %Clipboard%

These were my MSDN reference:
Enabling Internet Functionality
InternetOpen Function

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
Since URLDownloadToFile works, I suppose this is the answer:

Try changing Prx ? 3:1 with 4

URLDownloadToFile uses INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY (4).

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

URLDownloadToFile uses INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY (4).


Oh! Thanks Lexikos..
Does that mean I can make 4 default and remove Prx & PRB parameters?
If yes, will it slow down InternetOpen() considerably ?

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
It's probably slower (since it reads from the registry), but not by much I'd wager.

Does that mean I can make 4 default and remove Prx & PRB parameters?

Yes. Specifying 4 is like specifying 3 or 1 depending on proxy settings in the registry.

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

Specifying 4 is like specifying 3 or 1 depending on proxy settings in the registry.


I was able to guess that.. but feel comfortable hearing it from you.
Title Post/Code updated.. Many thanks Lexikos. :)

Elesar
  • Members
  • 696 posts
  • Last active: May 08 2015 09:51 PM
  • Joined: 28 Jun 2007
I will try this code out on Monday, as I am off for the weekend and about to go out of town. Thanks to both of you for the help, hope this works :D

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
Have a nice weeked, Elesar :)

Elesar
  • Members
  • 696 posts
  • Last active: May 08 2015 09:51 PM
  • Joined: 28 Jun 2007
Ok, good news and bad news...

Good news is that I did have a good weekend, and also that the new code allows examples 1 & 2 to complete perfectly.

Bad news is that example 3 kills immediately. I see the progress bar flash up, but the script exits as soon as it is shown.

I re-ran an old copy of the code and 1&2 fail with 3 working fine.

Both attempts were without alteration to the code as it was posted, so no Prx or PBP params.

As for the test you wanted me to run:
---------------------------
64
---------------------------
Proxy Enabled	: True
Proxy Server	: 192.168.37.5:8080
Proxy Override	: 192.168.0.0;172.0.0.0;10.0.0.0;192.168.37.58;192.168.37.0;192.168.47.0;192.168.57.0;192.168.77.0;172.16.30.66;172.16.30.91;172.16.70.60;192.168.207.160;192.168.37.230;172.16.30.80;172.16.30.88;172.16.30.89;<local>
---------------------------
OK   
---------------------------