Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > microsoft.public.scripting.vbscript > #11623 > unrolled thread

WriteLine fails with error 5 (bad argument) on a string ?

Started by"R.Wieser" <address@not.available>
First post2017-04-18 14:14 +0200
Last post2017-04-19 16:46 +0200
Articles 20 on this page of 55 — 4 participants

Back to article view | Back to microsoft.public.scripting.vbscript


Contents

  WriteLine fails with error 5 (bad argument) on a string ? "R.Wieser" <address@not.available> - 2017-04-18 14:14 +0200
    Re: WriteLine fails with error 5 (bad argument) on a string ? "Mayayana" <mayayana@invalid.nospam> - 2017-04-18 09:06 -0400
      Re: WriteLine fails with error 5 (bad argument) on a string ? "R.Wieser" <address@not.available> - 2017-04-18 16:44 +0200
        Re: WriteLine fails with error 5 (bad argument) on a string ? "Mayayana" <mayayana@invalid.nospam> - 2017-04-18 18:50 -0400
          Re: WriteLine fails with error 5 (bad argument) on a string ? "R.Wieser" <address@not.available> - 2017-04-19 11:39 +0200
            Re: WriteLine fails with error 5 (bad argument) on a string ? "Mayayana" <mayayana@invalid.nospam> - 2017-04-19 09:22 -0400
              Re: WriteLine fails with error 5 (bad argument) on a string ? "R.Wieser" <address@not.available> - 2017-04-19 17:27 +0200
                Re: WriteLine fails with error 5 (bad argument) on a string ? "Mayayana" <mayayana@invalid.nospam> - 2017-04-19 13:49 -0400
                  Re: WriteLine fails with error 5 (bad argument) on a string ? "R.Wieser" <address@not.available> - 2017-04-20 17:56 +0200
                    Re: WriteLine fails with error 5 (bad argument) on a string ? "Mayayana" <mayayana@invalid.nospam> - 2017-04-20 13:24 -0400
                      Re: WriteLine fails with error 5 (bad argument) on a string ? Ulrich Möller <knobbi38@arcor.de> - 2017-04-21 01:05 +0200
                        Re: WriteLine fails with error 5 (bad argument) on a string ? "Mayayana" <mayayana@invalid.nospam> - 2017-04-20 21:42 -0400
                          Re: WriteLine fails with error 5 (bad argument) on a string ? "R.Wieser" <address@not.available> - 2017-04-21 10:11 +0200
                      Re: WriteLine fails with error 5 (bad argument) on a string ? "R.Wieser" <address@not.available> - 2017-04-21 09:23 +0200
    Re: WriteLine fails with error 5 (bad argument) on a string ? "Mayayana" <mayayana@invalid.nospam> - 2017-04-18 09:57 -0400
      Re: WriteLine fails with error 5 (bad argument) on a string ? "R.Wieser" <address@not.available> - 2017-04-18 17:20 +0200
        Re: WriteLine fails with error 5 (bad argument) on a string ? "Mayayana" <mayayana@invalid.nospam> - 2017-04-18 14:27 -0400
          Re: WriteLine fails with error 5 (bad argument) on a string ? "R.Wieser" <address@not.available> - 2017-04-18 22:15 +0200
            Re: WriteLine fails with error 5 (bad argument) on a string ? "Mayayana" <mayayana@invalid.nospam> - 2017-04-18 18:30 -0400
              Re: WriteLine fails with error 5 (bad argument) on a string ? "R.Wieser" <address@not.available> - 2017-04-19 11:09 +0200
                Re: WriteLine fails with error 5 (bad argument) on a string ? "Mayayana" <mayayana@invalid.nospam> - 2017-04-19 09:23 -0400
                Re: WriteLine fails with error 5 (bad argument) on a string ? "Mayayana" <mayayana@invalid.nospam> - 2017-04-19 09:59 -0400
                  Re: WriteLine fails with error 5 (bad argument) on a string ? "R.Wieser" <address@not.available> - 2017-04-19 17:41 +0200
      Re: WriteLine fails with error 5 (bad argument) on a string ? GS <gs@v.invalid> - 2017-04-18 11:58 -0400
      Re: WriteLine fails with error 5 (bad argument) on a string ? GS <gs@v.invalid> - 2017-04-26 09:56 -0400
        Re: WriteLine fails with error 5 (bad argument) on a string ? "R.Wieser" <address@not.available> - 2017-04-26 16:35 +0200
          Re: WriteLine fails with error 5 (bad argument) on a string ? GS <gs@v.invalid> - 2017-04-26 10:44 -0400
        Re: WriteLine fails with error 5 (bad argument) on a string ? "Mayayana" <mayayana@invalid.nospam> - 2017-04-26 11:07 -0400
        Re: WriteLine fails with error 5 (bad argument) on a string ? "Mayayana" <mayayana@invalid.nospam> - 2017-04-26 16:29 -0400
          Re: WriteLine fails with error 5 (bad argument) on a string ? GS <gs@v.invalid> - 2017-04-26 21:26 -0400
            Re: WriteLine fails with error 5 (bad argument) on a string ? "Mayayana" <mayayana@invalid.nospam> - 2017-04-26 23:28 -0400
              Re: WriteLine fails with error 5 (bad argument) on a string ? GS <gs@v.invalid> - 2017-04-28 01:11 -0400
                Re: WriteLine fails with error 5 (bad argument) on a string ? "Mayayana" <mayayana@invalid.nospam> - 2017-04-28 09:28 -0400
                  Re: WriteLine fails with error 5 (bad argument) on a string ? GS <gs@v.invalid> - 2017-04-28 15:22 -0400
                    Re: WriteLine fails with error 5 (bad argument) on a string ? "Mayayana" <mayayana@invalid.nospam> - 2017-04-28 19:16 -0400
                      Re: WriteLine fails with error 5 (bad argument) on a string ? GS <gs@v.invalid> - 2017-04-28 22:08 -0400
                        Re: WriteLine fails with error 5 (bad argument) on a string ? GS <gs@v.invalid> - 2017-04-28 22:11 -0400
                          Re: WriteLine fails with error 5 (bad argument) on a string ? GS <gs@v.invalid> - 2017-04-28 22:17 -0400
                        Re: WriteLine fails with error 5 (bad argument) on a string ? GS <gs@v.invalid> - 2017-04-28 22:21 -0400
                          Re: WriteLine fails with error 5 (bad argument) on a string ? "Mayayana" <mayayana@invalid.nospam> - 2017-04-28 22:37 -0400
                            Re: WriteLine fails with error 5 (bad argument) on a string ? GS <gs@v.invalid> - 2017-04-29 00:01 -0400
                              Re: WriteLine fails with error 5 (bad argument) on a string ? GS <gs@v.invalid> - 2017-04-29 01:19 -0400
                            Re: WriteLine fails with error 5 (bad argument) on a string ? GS <gs@v.invalid> - 2017-04-29 01:46 -0400
                              Re: WriteLine fails with error 5 (bad argument) on a string ? GS <gs@v.invalid> - 2017-04-29 12:36 -0400
                                Re: WriteLine fails with error 5 (bad argument) on a string ? "Mayayana" <mayayana@invalid.nospam> - 2017-04-29 19:59 -0400
                                  Re: WriteLine fails with error 5 (bad argument) on a string ? GS <gs@v.invalid> - 2017-04-29 20:18 -0400
                          Re: WriteLine fails with error 5 (bad argument) on a string ? GS <gs@v.invalid> - 2017-04-28 23:50 -0400
                    Re: WriteLine fails with error 5 (bad argument) on a string ? "Mayayana" <mayayana@invalid.nospam> - 2017-04-28 19:29 -0400
                      Re: WriteLine fails with error 5 (bad argument) on a string ? GS <gs@v.invalid> - 2017-04-28 22:04 -0400
                        Re: WriteLine fails with error 5 (bad argument) on a string ? "Mayayana" <mayayana@invalid.nospam> - 2017-04-28 22:25 -0400
                          Re: WriteLine fails with error 5 (bad argument) on a string ? GS <gs@v.invalid> - 2017-04-28 22:31 -0400
    Re: WriteLine fails with error 5 (bad argument) on a string ? Ulrich Möller <knobbi38@arcor.de> - 2017-04-18 19:20 +0200
      Re: WriteLine fails with error 5 (bad argument) on a string ? "R.Wieser" <address@not.available> - 2017-04-18 19:58 +0200
        Re: WriteLine fails with error 5 (bad argument) on a string ? Ulrich Möller <knobbi38@arcor.de> - 2017-04-19 14:59 +0200
          Re: WriteLine fails with error 5 (bad argument) on a string ? "R.Wieser" <address@not.available> - 2017-04-19 16:46 +0200

Page 2 of 3 — ← Prev page 1 [2] 3  Next page →


#11639

From"Mayayana" <mayayana@invalid.nospam>
Date2017-04-19 09:23 -0400
Message-ID<od7o86$j4s$1@dont-email.me>
In reply to#11635
"R.Wieser" <address@not.available> wrote

| >   But it does require WinXP+.
|
| Yep, that would be a problem ...

  Welcome to the 20th century. :) 

[toc] | [prev] | [next] | [standalone]


#11640

From"Mayayana" <mayayana@invalid.nospam>
Date2017-04-19 09:59 -0400
Message-ID<od7qan$q6f$1@dont-email.me>
In reply to#11635
"R.Wieser" <address@not.available> wrote

| > If you check Depends you'll see it uses a few string parsing
| > functions from shlwapi.dll, but aside from that it's all basic
| > system stuff
|
| You're joking, right ?    If that is *all* it uses it *cannot* make a
| network connection *ever*.    But as it does ...
|

  Good question.
  Looking at the DLL as text, there seem to be a
lot of winsock error codes. I'm guessing it either
calls one of the winsock libs without linking, or
it incorporates winsock functionality. ws2_32.dll
is only 80 KB, so maybe Winhttp just incorporates
the whole thing -- sort of a winsock COM object.

[toc] | [prev] | [next] | [standalone]


#11643

From"R.Wieser" <address@not.available>
Date2017-04-19 17:41 +0200
Message-ID<58f784f8$0$750$e4fe514c@news.xs4all.nl>
In reply to#11640
Mayayana,

>   Good question.

> I'm guessing it either calls one of the winsock libs without linking

Dynamic loading.  Rather possible, as it definitily uses LoadLibrary (from
Kernel32).

> or it incorporates winsock functionality.

I would say thats quite a "duh!" :-)

The other possibility is that it simply does a static linking of the needed
libraries.

Although that is rather counter-productive, not needing to distribute any of
the IE related libraries (though, how IE is WS2_32 ?) would keep MS on the
good side of the thanwhile inspectors (that where there to make sure MS
would not try to sneak in IE anyway).

Regards,
Rudy Wieser


-- Origional message:
Mayayana <mayayana@invalid.nospam> schreef in berichtnieuws
od7qan$q6f$1@dont-email.me...
> "R.Wieser" <address@not.available> wrote
>
> | > If you check Depends you'll see it uses a few string parsing
> | > functions from shlwapi.dll, but aside from that it's all basic
> | > system stuff
> |
> | You're joking, right ?    If that is *all* it uses it *cannot* make a
> | network connection *ever*.    But as it does ...
>
>   Good question.
>   Looking at the DLL as text, there seem to be a
> lot of winsock error codes. I'm guessing it either
> calls one of the winsock libs without linking, or
> it incorporates winsock functionality. ws2_32.dll
> is only 80 KB, so maybe Winhttp just incorporates
> the whole thing -- sort of a winsock COM object.


[toc] | [prev] | [next] | [standalone]


#11628

FromGS <gs@v.invalid>
Date2017-04-18 11:58 -0400
Message-ID<od5cu8$opk$1@dont-email.me>
In reply to#11625
> "R.Wieser" <address@not.available> wrote
>
>> I've retrieved a webpages content using the XMLHTTP object, and than
>> attempted to write the "responseText" result into a file.
>
>   Out of curiosity.... Have you used WinHttpRequest?
> I've never used xmlhttp and don't know anything about it.
> Since it seems to be part of IE I don't think I'd want
> to use it.
>  In the past I've avoided API functions like UrlDownloadToFile
> that are really just IE calls. It seems very sloppy to me,
> writing software that leaves records in IE history and cache,
> and may be affected by IE settings.

Wow! I use this API but didn't know the IE part of it!

>   So some years ago I wrote winsock code for Interet functions.
> But awhile back someone pointed me to WinHttpRequest.
> It turns out to be a clean, simple way to make server requests,
> without the sloppy IE tie-in. Some of the methods use strings
> rather than variants, but it seems to work fine with VBScript.
> (I've only used it in VB6, but I've seen VBS code.) 

Sounds worth looking into...

-- 
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
  comp.lang.basic.visual.misc
  microsoft.public.vb.general.discussion

[toc] | [prev] | [next] | [standalone]


#11651

FromGS <gs@v.invalid>
Date2017-04-26 09:56 -0400
Message-ID<odq8ov$7et$1@dont-email.me>
In reply to#11625
>   So some years ago I wrote winsock code for Interet functions.
> But awhile back someone pointed me to WinHttpRequest.
> It turns out to be a clean, simple way to make server requests,
> without the sloppy IE tie-in. Some of the methods use strings
> rather than variants, but it seems to work fine with VBScript.
> (I've only used it in VB6, but I've seen VBS code.)

I've been looking into this and have come up short on examples for how to 
download files in place of using UrlDownloadToFile. Can you point me in the 
right direction? (I've hit a situation where my app keeps getting the older 
cache version of the file (Win10), not an updated version when my online form 
submits new data to it!)

-- 
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
  comp.lang.basic.visual.misc
  microsoft.public.vb.general.discussion

[toc] | [prev] | [next] | [standalone]


#11652

From"R.Wieser" <address@not.available>
Date2017-04-26 16:35 +0200
Message-ID<5900afe2$0$772$e4fe514c@news.xs4all.nl>
In reply to#11651
GS

Plugging "UrlDownloadToFile cache" into Google yielded this (second result):

http://stackoverflow.com/questions/75432/how-can-i-prevent-urldownloadtofile
-from-retrieving-from-the-cache

Regards,
Rudy Wieser


-- Origional message:
GS <gs@v.invalid> schreef in berichtnieuws odq8ov$7et$1@dont-email.me...
> >   So some years ago I wrote winsock code for Interet functions.
> > But awhile back someone pointed me to WinHttpRequest.
> > It turns out to be a clean, simple way to make server requests,
> > without the sloppy IE tie-in. Some of the methods use strings
> > rather than variants, but it seems to work fine with VBScript.
> > (I've only used it in VB6, but I've seen VBS code.)
>
> I've been looking into this and have come up short on examples for how to
> download files in place of using UrlDownloadToFile. Can you point me in
the
> right direction? (I've hit a situation where my app keeps getting the
older
> cache version of the file (Win10), not an updated version when my online
form
> submits new data to it!)
>
> --
> Garry
>
> Free usenet access at http://www.eternal-september.org
> Classic VB Users Regroup!
>   comp.lang.basic.visual.misc
>   microsoft.public.vb.general.discussion

[toc] | [prev] | [next] | [standalone]


#11653

FromGS <gs@v.invalid>
Date2017-04-26 10:44 -0400
Message-ID<odqbio$hrc$1@dont-email.me>
In reply to#11652
> GS
>
> Plugging "UrlDownloadToFile cache" into Google yielded this (second result):
>
> http://stackoverflow.com/questions/75432/how-can-i-prevent-urldownloadtofile
> -from-retrieving-from-the-cache
>
> Regards,
> Rudy Wieser
>
>
> -- Origional message:
> GS <gs@v.invalid> schreef in berichtnieuws odq8ov$7et$1@dont-email.me...
>>>   So some years ago I wrote winsock code for Interet functions.
>>> But awhile back someone pointed me to WinHttpRequest.
>>> It turns out to be a clean, simple way to make server requests,
>>> without the sloppy IE tie-in. Some of the methods use strings
>>> rather than variants, but it seems to work fine with VBScript.
>>> (I've only used it in VB6, but I've seen VBS code.)
>> 
>> I've been looking into this and have come up short on examples for how to
>> download files in place of using UrlDownloadToFile. Can you point me in the
>> right direction? (I've hit a situation where my app keeps getting the older
>> cache version of the file (Win10), not an updated version when my online 
>> form submits new data to it!)
>> 
>> --
>> Garry
>> 
>> Free usenet access at http://www.eternal-september.org
>> Classic VB Users Regroup!
>>   comp.lang.basic.visual.misc
>>   microsoft.public.vb.general.discussion

Thanks, Rudy! I already did this but decided to explore possibly using 
WinHttpRequest since it 'apparently' doesn't use caches...

-- 
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
  comp.lang.basic.visual.misc
  microsoft.public.vb.general.discussion

[toc] | [prev] | [next] | [standalone]


#11656

From"Mayayana" <mayayana@invalid.nospam>
Date2017-04-26 11:07 -0400
Message-ID<odqcv3$nat$1@dont-email.me>
In reply to#11651
"GS" <gs@v.invalid> wrote

| I've been looking into this and have come up short on examples for how to
| download files in place of using UrlDownloadToFile. Can you point me in 
the
| right direction? (I've hit a situation where my app keeps getting the 
older
| cache version of the file (Win10), not an updated version when my online 
form
| submits new data to it!)
|

   I don't have time right now to pick apart
the code, but I'd be happy to send it to you
or clean it up later.

  The calls are very simple, but there are a few
things to know. I ended up writing a function to
return error strings, which is handy. I also
have a function for setting options. There are
some details to know there. For instance, XP
doesn't support higher than TLS 1.0:

Private Sub TLSSetOptions(AllowSecurityErrors As Boolean)
 On Error Resume Next
   With WHR
    .SetRequestHeader "Accept-Encoding", "gzip"
    .SetRequestHeader "Host", sDefServer
    .SetRequestHeader "User-Agent", UAgent
    .Option(WinHttpRequestOption_UserAgentString) = UAgent  'useragent
   If AllowSecurityErrors = False Then
     .Option(WinHttpRequestOption_SslErrorIgnoreFlags) = OptErrIgnore 
'ignore ssl errors
   Else
     .Option(WinHttpRequestOption_SslErrorIgnoreFlags) = OptErrDontIgnore 
'don't ignore ssl errors
   End If
    .Option(WinHttpRequestOption_SecureProtocols) = OptTLS1_0  ' use TLS 
1.0. 1.1 and 1.2 cause error in XP.
    .Option(WinHttpRequestOption_EnablePassportAuthentication) = False 
'block passport auth
    .Option(WinHttpRequestOption_EnableCertificateRevocationCheck) = False 
' block check of revoked certificate
   End With
End Sub

  The calling code is slightly enmeshed so I can't reprint
it here, but it's simple. I used it in this (link below), after
giving up on trying to do encryption from scratch over
winsock. It's far simpler than winsock, and I've found it
very dependable. There isn't quite so much control as
there is with winsock, but more than you get with
wininet:

http://www.jsware.net/jsware/gmapkit.php5

  There was a discussion in the VB6 group at the time I
was working out this code.
  I probably had the usual argument with Arne about how
he thought I was doing everything wrong and I thought
he was out to lunch and avoiding being helpful. :)
But those arguments at least have the benefit of airing
out the issues.


[toc] | [prev] | [next] | [standalone]


#11660

From"Mayayana" <mayayana@invalid.nospam>
Date2017-04-26 16:29 -0400
Message-ID<odqvpo$qop$1@dont-email.me>
In reply to#11651
Garry,

  See if this code makes sense. I had to pull it from my program
code in pieces, but I think it will be clear when you read it.
Note: I provide the option to accept gzip encoding. That
seems polite these days. I let the server know that in the header.
But that also means one has to be prepared to decode gzip.

  Most of the error issues never happen in my use of winhttp,
but I wanted to write it to be as informative and flexible as
possible. So if the call fails to download a file I run the result
through my error parser and then may 1) show a message asking
how to proceed or 2) try the call again with lower security
restrictions.

   Another note: XP can't handle TLS 1.1. Win7 can. If you
want to test OS version you can make that option more
flexible. But be careful. Vista/7 and later will lie about OS
version. If someone runs in XP mode you'll be told you're
running on XP. But that doesn't mean XP code will work
properly. I just settled for TLS 1.0 figuring that highest
security for Google maps is not critical.

  At the end of the main function (which is in a UC) the
downloaded file is in a byte array and an event has been
raised to deal with it.

  And without further ado, here's the code. Wordwrap is going
to be horrendous here. Sorry.....

'declares:
Private Const OptTLS1_0 As Long = &H80&

  '-- these fail in XP -------------------
Private Const OptTLS1_1 As Long = &H200&
Private Const OptTLS1_2 As Long = &H800&
Private Const OptAnyTLS As Long = &HA80&  'OptTLS1_0 Or OptTLS1_1 Or 
OptTLS1_2

Private Const OptErrIgnore As Long = &H3300&
Private Const OptErrDontIgnore As Long = &H0&


' code within function TLSGetImage to get a file.
' This doesn't need to be an image file. I just had
'reasons to deal with different files differently.
' I didn't include all of function here, but the gist
'of it should be clear.

 If BooTLS = True Then
     sFullURL = "https://somehwere.com/file.jpg"
Else
     sFullURL = "http://somehwere.com/file.jpg"
 End If
   Set WHR = New WinHttpRequest
     WHR.open "GET", sFullURL, False
     TLSSetOptions True
     Err.Clear
     On Error Resume Next
     WHR.Send
       If Err.Number <> 0 Then
         LRet = ProcessWNRError(Err.Number, ErrInt)
         Select Case LRet
           '-- return 0 if dealt with (and should quit)
             '--   -1 to show winhttp error and quit,
             '--1 for security options.
          Case 0 'either didn't want to continue after cert error or already 
showed error msg.
             sErr = "Server error: " & CStr(ErrInt) & " - " & 
Err.Description
             Set WHR = Nothing
             TLSGetImage = -1
             GoTo FinishUp
           Case -1
             sErr = "Server error: " & CStr(ErrInt) & " - " & 
Err.Description
             MsgBox "Server error: " & CStr(ErrInt) & " - " & 
Err.Description
             Set WHR = Nothing
             TLSGetImage = -1
             GoTo FinishUp
           Case Else  ' 1
             WHR.open "GET", sFullURL, False
             TLSSetOptions False  '--try again without security errors 
blocking.
             WHR.Send
         End Select
       End If

      LServerCode = WHR.Status
      sServerCode = CStr(LServerCode)

     If LServerCode <> 200 Then
       sErr = "Server error: " & sServerCode
       If Err.Number <> 0 Then sErr = sErr & "Program error: " & Err.Number 
& " - " & Err.Description
       TLSGetImage = -2
       Set WHR = Nothing
       GoTo FinishUp
     End If

  sHeader1 = WHR.GetAllResponseHeaders
       A1 = WHR.ResponseBody
    Set WHR = Nothing
       If InStr(sHeader1, "Content-Encoding") > 0 And InStr(sHeader1, 
"gzip") > 0 Then
          AFile = GUnzip2(A1, LRet)
          If LRet <> 0 Then
            sErr = "Unzip error: " & CStr(LRet)
            TLSGetImage = -2
          End If
       Else
          AFile = A1
       End If

FinishUp:
   RaiseEvent OnFinish(TLSGetImage, sErr)
'-function ends here----

Private Sub TLSSetOptions(AllowSecurityErrors As Boolean)
 On Error Resume Next
   With WHR
    .SetRequestHeader "Accept-Encoding", "gzip"
    .SetRequestHeader "Host", sDefServer  '-- like www.somewhere.com
    .SetRequestHeader "User-Agent", UAgent '-- like a browser UA, or allow 
user to se it.
    .Option(WinHttpRequestOption_UserAgentString) = UAgent  'useragent
   If AllowSecurityErrors = False Then
     .Option(WinHttpRequestOption_SslErrorIgnoreFlags) = OptErrIgnore 
'ignore ssl errors
   Else
     .Option(WinHttpRequestOption_SslErrorIgnoreFlags) = OptErrDontIgnore 
'don't ignore ssl errors
   End If
    .Option(WinHttpRequestOption_SecureProtocols) = OptTLS1_0  ' use TLS 
1.0. 1.1 and 1.2 cause

error in XP.
    .Option(WinHttpRequestOption_EnablePassportAuthentication) = False 
'block passport auth
    .Option(WinHttpRequestOption_EnableCertificateRevocationCheck) = False 
' block check of

revoked certificate
   End With
End Sub

'------------------------------------------------------

'error parser code:

'-- return 0 if dealt with (and should quit), -1 to show winhttp error and 
quit, 1 for security options.
Public Function ProcessWNRError(LErr As Long, IntError As Integer) As Long
  Dim i3 As Integer
  Dim LRet As Long
  On Error Resume Next
     i3 = GetLowInt(LErr)
  Select Case i3
    Case 12029  'Returned if connection to the server failed.
      MsgBox "Unable to connect. If your computer is otherwise connecting to 
the Internet the problem

may be with a firewall or anti-virus program blocking GMap Kit.", 64, "GMap 
Kit Network Error"
      ProcessWNRError = 0

    Case 12009  'A request to WinHttpQueryOption or WinHttpSetOption 
specified an invalid option

value.
      LRet = MsgBox("Error with WinHTTP options. If you are using TLS for 
secure connection[ see

program settings] try not using it.", 64, "GMap Kit Network Error")
      ProcessWNRError = 0

    Case 12037 'cert outdated.
       LRet = MsgBox("Certificate is expired. This could be a security risk. 
Do you want to continue?",

36, "GMap Kit Network Error")
       If LRet = 6 Then ProcessWNRError = 1 Else ProcessWNRError = 0

    Case 12038 'Returned when a certificate CN name does not match the 
passed value (equivalent to

a CERT_E_CN_NO_MATCH error).
       LRet = MsgBox("Security certificate name does not match. This could 
be a security risk. Do you

want to continue?", 36, "GMap Kit Network Error")
       If LRet = 6 Then ProcessWNRError = 1 Else ProcessWNRError = 0

    Case 12170  'Indicates that a certificate has been revoked (equivalent 
to CRYPT_E_REVOKED).
       LRet = MsgBox("Certificate has been revoked. This could be a security 
risk. Do you want to

continue?", 36, "GMap Kit Network Error")
       If LRet = 6 Then ProcessWNRError = 1 Else ProcessWNRError = 0

    Case 12157 'Indicates that an error occurred having to do with a secure 
channel (equivalent to

error codes that begin with "SEC_E_" and "SEC_I_" listed in the "winerror.h" 
header file).
       LRet = MsgBox("Error with WinHTTP options. If you are using TLS for 
secure connection[ see

program settings] and this error continues, try not using it.", 64, "GMap 
Kit Network Error")
       ProcessWNRError = 0

    Case 12175 'One or more errors were found in the Secure Sockets Layer 
(SSL) certificate sent by

the server. To determine what type of error was encountered, check for a

WINHTTP_CALLBACK_STATUS_SECURE_FAILURE notification in a status callback 
function. For more

information, see WINHTTP_STATUS_CALLBACK.
       LRet = MsgBox("Errors in certificate sent by server. This could be a 
security risk. Do you want to

continue?", 36, "GMap Kit Network Error")
       If LRet = 6 Then ProcessWNRError = 1 Else ProcessWNRError = 0

    Case 12045 'Indicates that a certificate chain was processed, but 
terminated in a root certificate

that is not trusted by the trust provider (equivalent to 
CERT_E_UNTRUSTEDROOT).
        LRet = MsgBox("Certificate sent by server is not trusted. This could 
be a security risk. Do you

want to continue?", 36, "GMap Kit Network Error")
       If LRet = 6 Then ProcessWNRError = 1 Else ProcessWNRError = 0

    Case 12169 'Indicates that a certificate is invalid (equivalent to 
errors such as CERT_E_ROLE,

CERT_E_PATHLENCONST, CERT_E_CRITICAL, CERT_E_PURPOSE, CERT_E_ISSUERCHAINING,

CERT_E_MALFORMED and CERT_E_CHAINING).
       LRet = MsgBox("Certificate sent by server is invalid. This could be a 
security risk. Do you want to

continue?", 36, "GMap Kit Network Error")
       If LRet = 6 Then ProcessWNRError = 1 Else ProcessWNRError = 0

    Case Else
      ProcessWNRError = -1 'show basic error info and quit.
  End Select

End Function


Public Function GetLowInt(LongIn As Long) As Integer
  On Error Resume Next
   If (LongIn And &HFFFF&) > &H7FFF Then
      GetLowInt = (LongIn And &HFFFF&) - &H10000
   Else
      GetLowInt = LongIn And &HFFFF&
   End If
End Function


'------------- gzip code:

Public Type zStream
    next_in As Long
    avail_in As Long
    total_in As Long
    next_out As Long
    avail_out As Long
    total_out As Long
    MSG As Long
    state As Long
    zalloc As Long
    zfree As Long
    opaque As Long
    data_type As Long
    adler As Long
    reserved As Long
 End Type

Public Type GZHead   ' 10 bytes
 ID1 As Byte '31
 ID2 As Byte '139
 CM As Byte   '8 compression method. (8 is only option!)
 FLG As Byte  ' flags.
 MTime As Long ' modified date. set to 0 on write. ignore on read.
 XFL As Byte  '0
 OS As Byte '0
End Type

Private Const Z_FINISH As Long = 4
Private Const Z_STREAM_END = 1


Private Declare Function inflateInit2 Lib "zlibw125.dll" Alias 
"inflateInit2_" (strm As zStream, ByVal

windowBits As Long, ByVal ZLibVersion As String, ByVal zStream_size As Long) 
As Long
 Private Declare Function inflate Lib "zlibw125.dll" (vStream As zStream, 
ByVal vflush As Long) As

Long
 Private Declare Function inflateEnd Lib "zlibw125.dll" (vStream As zStream) 
As Long

Public Function GUnzip2(AIn() As Byte, LErr As Long) As Byte()
  Dim A2() As Byte
  Dim LRet As Long, LenDData As Long, LenCData As Long
  Dim ZS As zStream
    On Error Resume Next
   LenCData = UBound(AIn) + 1
   CopyMemory LenDData, AIn(UBound(AIn) - 3), 4 '--get total size.
    ReDim A2(LenDData - 1) As Byte
     With ZS
       .zalloc = 0
       .zfree = 0
       .opaque = 0
       .avail_in = LenCData
       .avail_out = LenDData
       .next_in = VarPtr(AIn(0))
       .next_out = VarPtr(A2(0))
     End With
       LRet = inflateInit2(ZS, 47, "1.2.5.0", Len(ZS))
         If LRet <> 0 Then
           LErr = LRet 'negative number errors.
           Exit Function
         End If
       LRet = inflate(ZS, Z_FINISH)
         If LRet = 1 Then LRet = 0 '-- 0 is OK. 1 is returned when the whole 
thing has been

decompressed.
       LErr = LRet
       LRet = inflateEnd(ZS)
         If (LErr <> 0) Then Exit Function
     '-- make sure transfer of array is last call to avoid duplication of 
array.
       GUnzip2 = A2
End Function




[toc] | [prev] | [next] | [standalone]


#11661

FromGS <gs@v.invalid>
Date2017-04-26 21:26 -0400
Message-ID<odrh5j$gd1$1@dont-email.me>
In reply to#11660
Wow! Lots to digest and certainly not as simple as UrlDownloadToFile. Perhaps a 
wrapper is the way to go where I can use it in similar fashion 
(sourceFile,targetFile args)!!

-- 
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
  comp.lang.basic.visual.misc
  microsoft.public.vb.general.discussion

[toc] | [prev] | [next] | [standalone]


#11662

From"Mayayana" <mayayana@invalid.nospam>
Date2017-04-26 23:28 -0400
Message-ID<odroca$qnn$1@dont-email.me>
In reply to#11661
"GS" <gs@v.invalid> wrote

| Wow! Lots to digest and certainly not as simple as UrlDownloadToFile. 
Perhaps a
| wrapper is the way to go where I can use it in similar fashion
| (sourceFile,targetFile args)!!
|

   Yes. It's easier than it looks. I just wanted to pad
it with all the luxuries, like gzip support and extensive
error handling. But the main advantage is that it handles
https transparently. And even without that, winsock
is a lot more work.

  On the other hand, there's always the WB control, which
is pretty much UrlDownloadToFile. Navigate has flags to
avoid cache and history. But personally I find that kind
of hokey.

 There's also a very simple method provided by the
userControl. Karl Peterson has a sample at his site.

http://vb.mvps.org/samples/NetGrab/

  For some reason Filzip says it's not a valid ZIP, but
7-Zip opened it. Karl's code is very simple. Kind of
a hidden gem. But I don't think it does SSL/TLS,
and that's becoming something that people expect
these days. 

[toc] | [prev] | [next] | [standalone]


#11663

FromGS <gs@v.invalid>
Date2017-04-28 01:11 -0400
Message-ID<oduioc$ahg$1@dont-email.me>
In reply to#11662
> "GS" <gs@v.invalid> wrote
>
>> Wow! Lots to digest and certainly not as simple as UrlDownloadToFile.  
>> Perhaps a wrapper is the way to go where I can use it in similar fashion
>> (sourceFile,targetFile args)!!
>> 
>
>    Yes. It's easier than it looks. I just wanted to pad
> it with all the luxuries, like gzip support and extensive
> error handling. But the main advantage is that it handles
> https transparently. And even without that, winsock
> is a lot more work.
>
>   On the other hand, there's always the WB control, which
> is pretty much UrlDownloadToFile. Navigate has flags to
> avoid cache and history. But personally I find that kind
> of hokey.
>
>  There's also a very simple method provided by the
> userControl. Karl Peterson has a sample at his site.
>
> http://vb.mvps.org/samples/NetGrab/
>
>   For some reason Filzip says it's not a valid ZIP, but
> 7-Zip opened it. Karl's code is very simple. Kind of
> a hidden gem. But I don't think it does SSL/TLS,
> and that's becoming something that people expect
> these days. 

Karl's UC is a great tool but I'm working with Excel VBA here and so I'm going 
to plug through your code because nothing I've found is working properly (just 
getting empty file)!

-- 
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
  comp.lang.basic.visual.misc
  microsoft.public.vb.general.discussion

[toc] | [prev] | [next] | [standalone]


#11664

From"Mayayana" <mayayana@invalid.nospam>
Date2017-04-28 09:28 -0400
Message-ID<odvfss$5sa$1@dont-email.me>
In reply to#11663
"GS" <gs@v.invalid> wrote

| Karl's UC is a great tool but I'm working with Excel VBA here and so I'm 
going
| to plug through your code because nothing I've found is working properly 
(just
| getting empty file)!
|

  I'm sorry that I don't have a clean UC to offer you.
I never wrote a straight winhttp UC. I use it to call
Google Maps server, and adapted it from a winsock
UC. (The winsock file-downloading UC is available on
my VB6 page, but it doesn't do https.)

  The actual winhttp code is actually very minimal.
(At least it seems that way to me after using winsock.)

 The rest of my code is mostly specifics for my program.
JSON parsing and such. (Google, like everyone else,
have gone bonkers for both XML and JSON. I half expect
that Microsoft, one of these days, will come out with a
programming language composed of nothing but curly
brackets, GUIDs and XML.)

   If you look at the main function code you'll see that
it's mostly a lot of potential error handling. Comparing
it to the error info function, ProcessWNRError, will
explain the steps in the Select Case filter. In theory
you could cut out everything but the lines with the
WHR (winhttprequest) object and then just check to
see if your array is holding anything and return the server
response code (200, 404, etc).

  I was writing freeware and wanted to be sure that if
maps didn't come through, the end user would at least
have as much info as possible to figure out whether it's
their connection, the Google server, an invalid request,
or whatever. Especially given the complications of https.
Part of the code is to provide the option to relax
certificate strictness if necessary. It's ridiculously common
for sites to let their certificates expire or to use their
somewhere.com cert for their swhere.com domain. If
that's not dealt with then either you have no security
or you fail to get files half the time. On the other hand,
if you don't care about https then you can skip all that
and just check the server header for error code. (200,
404, etc)

   That's a nice aspect of winhttp. It's a convenient
compromise between the dummy functionality IE wrapper
of wininet and the closer control of winsock.
GetAllResponseHeaders returns the server response and
SetRequestHeader allows you to customize the server
conversation from your end. So you get most of the
control of winsock without the work.

[toc] | [prev] | [next] | [standalone]


#11665

FromGS <gs@v.invalid>
Date2017-04-28 15:22 -0400
Message-ID<oe04jm$hcc$1@dont-email.me>
In reply to#11664
Thanks for the followup! It'll be a while before I get the time to sort through 
and pull only what I need to read a text file of form results...

BTW:
I continued looking into using php for form processing to a text file AFTER I 
left you a contact msg on your website. That's working very well now nd so my 
focus is on download/read an online file. Here's what I'm using with 
WinHttpRequest.5.1...

  Set oWHR = CreateObject("WinHttp.WinHttpRequest.5.1")
  oWHR.Open "GET", sSrcFile, False
    ' Use HTTPREQUEST_SETCREDENTIALS_FOR_PROXY if user and password
    ' is for proxy, not for download the file.
    ' objHTTP.SetCredentials "User", "Password", 
HTTPREQUEST_SETCREDENTIALS_FOR_SERVER
  oWHR.Send

  If oWHR.Status = 200 Then
    Dim oADO
    Set oADO = CreateObject("ADODB.Stream")
    With oADO
      .Type = 2: .Open: .Write oWHR.ResponseBody: .SaveToFile sTgtFile: .Close
    End With
  End If

..which, so far, just creates an empty file. Can you see where something is 
missing?

-- 
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
  comp.lang.basic.visual.misc
  microsoft.public.vb.general.discussion

[toc] | [prev] | [next] | [standalone]


#11666

From"Mayayana" <mayayana@invalid.nospam>
Date2017-04-28 19:16 -0400
Message-ID<oe0ibf$hg$1@dont-email.me>
In reply to#11665
"GS" <gs@v.invalid> wrote

  You're doing this in VBS? I thought you were using
VB. I've never done it in VBS. There are several parts
here I'm not sure about. I've never needed/used
SetCredentials. You didn't need to adjust the send
header at all? You didn't check the error and I don't
know if you're using https, so that leaves unanswered
questions.

 I'm curious why you set the version of winhttp. I
guess it's fine, but won't that limit you if you run
from a machine that has, say, 5.2?

  It appears you got a 200 response if you're writing
to disk. So maybe all the above doesn't matter.  I'm
not really familiar with ADODB and you've scrunched it
all into a dubious one-liner, so I also don't know how
to troubleshoot that. You realize the return is a byte
array? I don't know what Type 2 is. Hopefully that's
binary.


|
|  Set oWHR = CreateObject("WinHttp.WinHttpRequest.5.1")
|  oWHR.Open "GET", sSrcFile, False
|    ' Use HTTPREQUEST_SETCREDENTIALS_FOR_PROXY if user and password
|    ' is for proxy, not for download the file.
|    ' objHTTP.SetCredentials "User", "Password",
| HTTPREQUEST_SETCREDENTIALS_FOR_SERVER
|  oWHR.Send
|
|  If oWHR.Status = 200 Then
|    Dim oADO
|    Set oADO = CreateObject("ADODB.Stream")
|    With oADO
|      .Type = 2: .Open: .Write oWHR.ResponseBody: .SaveToFile sTgtFile: 
.Close
|    End With
|  End If
|
| ..which, so far, just creates an empty file. Can you see where something 
is
| missing?
|
| -- 
| Garry
|
| Free usenet access at http://www.eternal-september.org
| Classic VB Users Regroup!
|  comp.lang.basic.visual.misc
|  microsoft.public.vb.general.discussion 

[toc] | [prev] | [next] | [standalone]


#11669

FromGS <gs@v.invalid>
Date2017-04-28 22:08 -0400
Message-ID<oe0scs$o2m$1@dont-email.me>
In reply to#11666
This is VB[A} code, not VBS!

Type 2 is text because that's what the download file is, not a binary file. 
(Though I'll change it to Type 1 and see if that makes a difference.

ADODB is what the samples I found online are using to write .ResponseBody to 
the local file...

-- 
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
  comp.lang.basic.visual.misc
  microsoft.public.vb.general.discussion

[toc] | [prev] | [next] | [standalone]


#11670

FromGS <gs@v.invalid>
Date2017-04-28 22:11 -0400
Message-ID<oe0sja$oir$1@dont-email.me>
In reply to#11669
> This is VB[A} code, not VBS!
>
> Type 2 is text because that's what the download file is, not a binary file. 
> (Though I'll change it to Type 1 and see if that makes a difference.
>
> ADODB is what the samples I found online are using to write .ResponseBody to 
> the local file...

Aha.., Type 1 works! Thanks for catching that...

-- 
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
  comp.lang.basic.visual.misc
  microsoft.public.vb.general.discussion

[toc] | [prev] | [next] | [standalone]


#11671

FromGS <gs@v.invalid>
Date2017-04-28 22:17 -0400
Message-ID<oe0stt$p90$1@dont-email.me>
In reply to#11670
> Aha.., Type 1 works! Thanks for catching that...

Wow! This method is orders of magnitude faster; -UrlDownloadToFile took a few 
seconds (didn't actually time it, just counted in my head) and WinHttpRequest 
was done in a blink!

I removed the version spec...

-- 
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
  comp.lang.basic.visual.misc
  microsoft.public.vb.general.discussion

[toc] | [prev] | [next] | [standalone]


#11672

FromGS <gs@v.invalid>
Date2017-04-28 22:21 -0400
Message-ID<oe0t62$pqi$1@dont-email.me>
In reply to#11669
> This is VB[A} code, not VBS!
>
> Type 2 is text because that's what the download file is, not a binary file. 
> (Though I'll change it to Type 1 and see if that makes a difference.
>
> ADODB is what the samples I found online are using to write .ResponseBody to 
> the local file...

Oops.., spoke too soon. Now I'm getting an empty file again.
Back to the drawing board...

-- 
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
  comp.lang.basic.visual.misc
  microsoft.public.vb.general.discussion

[toc] | [prev] | [next] | [standalone]


#11675

From"Mayayana" <mayayana@invalid.nospam>
Date2017-04-28 22:37 -0400
Message-ID<oe0u55$t06$1@dont-email.me>
In reply to#11672
"GS" <gs@v.invalid> wrote

| Oops.., spoke too soon. Now I'm getting an empty file again.
| Back to the drawing board...

  It's always a byte array, but you can also try
ResponseText. I haven't bothered. I just handle
a byte array because I get different file types.

VBA can't do just a basic write, like this?

FF = FreeFile()
    Open sPath For Binary As #FF
        Put #FF, , AFile
    Close #FF

  I don't see why you'd need to bring in something
like adodb. My understanding is that's something
mainly for scripting. Another dependency. 

[toc] | [prev] | [next] | [standalone]


Page 2 of 3 — ← Prev page 1 [2] 3  Next page →

Back to top | Article view | microsoft.public.scripting.vbscript


csiph-web