-
Jan 22nd, 2020, 05:02 AM
#1
Thread Starter
Addicted Member
URLDownloadToFile error codes
Hello,
I find some error codes but I have an error 126 which I do not understand.
Here's how I get 126
Code:
lngReturn = URLDownloadToFile(0, URL, LocalFilename, BINDF_GETNEWESTVERSION, 0)
...
MsgTxt = "Download error " & CStr(lngReturn)
Most of the time everything works fine without error, so the call is not in issue.
What does 126 mean?
Thank you
-
Jan 22nd, 2020, 05:18 AM
#2
Re: URLDownloadToFile error codes
In some older project I have these definitions:
Code:
Public Enum URLDownloadErrConstants
udErrAborted = &H80004004
udErrDestFileExists = &H800C0001
udErrInvalidUrl = &H800C0002
udErrNoSession = &H800C0003
udErrCannotConnect = &H800C0004
udErrResourceNotFound = &H800C0005
udErrObjectNotFound = &H800C0006
udErrDataNotAvailable = &H800C0007
udErrDownloadFailure = &H800C0008
udErrAuthenticationRequired = &H800C0009
udErrNoValidMedia = &H800C000A
udErrConnectionTimeout = &H800C000B
udErrInvalidRequest = &H800C000C
udErrUnknownProtocol = &H800C000D
udErrSecurityProblem = &H800C000E
udErrCannotLoadData = &H800C000F
udErrCannotInstantiateObject = &H800C0010
udErrRedirectFailed = &H800C0014
udErrRedirectToDir = &H800C0015
udErrCannotLockRequest = &H800C0016
End Enum
Do you use it on WinXP or Win2000??
Last edited by Arnoutdv; Jan 22nd, 2020 at 05:22 AM.
-
Jan 22nd, 2020, 06:00 AM
#3
Thread Starter
Addicted Member
Re: URLDownloadToFile error codes
Thanks for the list, I had found it already, I don't see the 126 (=&H7E) code.
I use it on Win 10 but have a lot of other users on I don't know which operating system.
-
Jan 22nd, 2020, 07:29 AM
#4
Re: URLDownloadToFile error codes
No I don't see an error 126 either.
That's why I asked about W2K and XP, because the only result on Google using URLDownloadToFile and error 126 was related to W2K and XP
-
Jan 22nd, 2020, 09:46 AM
#5
Re: URLDownloadToFile error codes
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Jan 22nd, 2020, 10:16 AM
#6
Hyperactive Member
Re: URLDownloadToFile error codes
Slightly off topic but recently I've had problems with URLDownloadToFile. Regardless of the flag I pass in (BINDF_GETNEWESTVERSION), I get the cached version of the file rather than the latest one. This used to work for many years but I just noticed recently that it no longer does. Wonder if it's a Win10 thing?
-
Jan 24th, 2020, 02:27 AM
#7
Re: URLDownloadToFile error codes
Slightly off topic but recently
i had this problem recently and found the server had changed to https, but i was still supplying a url to http
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Jan 24th, 2020, 11:26 AM
#8
Thread Starter
Addicted Member
Re: URLDownloadToFile error codes
Originally Posted by Zvoni
No, it is empty because I forgot do define BINDF_GETNEWESTVERSION :-)
I repeat that most of the time my URLDownoladToFile works fine, only one error 126 for thousands of calls on hundreds different machines.
I replaced it by zero, it works as well.
-
Jan 30th, 2020, 11:12 AM
#9
Thread Starter
Addicted Member
Re: URLDownloadToFile error codes
Nobody has an idea about error 126 ?
-
Jan 30th, 2020, 11:59 AM
#10
Re: URLDownloadToFile error codes
other codes
USE_EXTEND_BINDING &H800C0017
TERMINATED_BIND &H800C0018
INVALID_CERTIFICATE &H800C0019
CODE_DOWNLOAD_DECLINED &H800C0100
RESULT_DISPATCHED &H800C0200
CANNOT_REPLACE_SFP_FILE &H800C0300
CODE_INSTALL_SUPPRESSED &H800C0400
CODE_INSTALL_BLOCKED_BY_HASH_POLICY &H800C0500
not sure what 126/7E is.
this API is calling a lot more functions that we dont see,
if you want full control you should not use this API, instead a bunch of functions like open, progress, transfer, status, close etc.
-
Jan 30th, 2020, 12:00 PM
#11
Hyperactive Member
Re: URLDownloadToFile error codes
We should be able to query "urlmon.dll" to get an error description for this but when I try to, I get no additional information. Here's partial code (all constants and API calls are not defined in here. it's just partial to show you how to did this)
Code:
Dim lngModuleHandle As Long
Dim strModule As String
Dim lngErrNum As Long
Dim lngMsgLen As Long
Dim lngPointerBuffer As Long
strModule = "urlmon.dll"
lngErrNum = 126
'get a handle to urlmon.dll
lngModuleHandle = GetModuleHandleW(StrPtr(strModule))
'load the module, if it's not loaded already
If lngModuleHandle = 0 Then
lngModuleHandle = LoadLibraryW(StrPtr(strModule))
End If
'get error message description from the DLL itself
lngMsgLen = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER Or FORMAT_MESSAGE_FROM_HMODULE Or FORMAT_MESSAGE_IGNORE_INSERTS, ByVal lngModuleHandle, lngErrNum, ByVal 0&, VarPtr(lngPointerBuffer), ByVal 0&, ByVal 0&)
If lngMsgLen = 0 Then
MsgBox "No further information is available"
Else
'retrieve message from the buffer
'(code omitted since it's not relevant to this discussion)
End If
'unload the module
FreeLibrary lngModuleHandle
When I run this I get lngMsgLen = 0, which means that there's no information available for error number 126.
Last edited by AAraya; Jan 30th, 2020 at 12:16 PM.
-
Jan 30th, 2020, 12:15 PM
#12
Hyperactive Member
Re: URLDownloadToFile error codes
Are you seeing a value of 126 in the lngReturn variable or in Err.LastDllError?
It doesn't make sense as a possible lngReturn value from the URLDownloadToFile call. But as an error in Err.LastDllError it would mean that "the module could not be found". Which I believe indicates that there was an issue with the urlmon.dll?
-
Mar 7th, 2020, 06:08 AM
#13
Thread Starter
Addicted Member
Re: URLDownloadToFile error codes
Sorry, I didn't saw your reply because I was 3 weeks out.
As I said in my first post here's how I get 126
Code:
lngReturn = URLDownloadToFile(0, URL, LocalFilename, BINDF_GETNEWESTVERSION, 0)
...
MsgTxt = "Download error " & CStr(lngReturn)
126 is the lngReturn contents.
-
Mar 7th, 2020, 09:32 AM
#14
Re: URLDownloadToFile error codes
What exactly is the API declare for URLDownloadToFile?
HRESULTs are errors only if the value is negative so 126 is not an error but a success result w/ info.
cheers,
</wqw>
-
Mar 6th, 2021, 11:16 AM
#15
New Member
Re: URLDownloadToFile error codes
I don't have Win10, instead i have Win7 - maybe this will help. On Win7 "URLDownloadToFile" is not a "FUNCTION", it's a "SUB" and the last Param "TLPBINDSTATUSCALLBACK" is "BYVAL" not "BYREF". Because this is a "SUB", that variable "lngReturn" should not be there. So, i will write an example:
' In General Declaration
Private Declare Sub URLDownloadToFile Lib "URLMON.dll" Alias "URLDownloadToFileA" (ByVal lpunknown As Long, ByVal lpcstr As String, ByVal lpcstr As String, ByVal dword As Long, ByVal TLPBINDSTATUSCALLBACK As Long)
' In button i assume
URLDownloadToFile 0&, "https://example/NotMe.exe", "NotMe.exe", 0&, 0&
So, this will download a file in same directory, where is EXE without an error.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|