Results 1 to 2 of 2

Thread: WinInet API Binary D/L

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Location
    New York
    Posts
    2

    Talking

    PLEASE HELP! I hope the description here is clear enough- if not, email me and I'll update it.

    We're creating a dll that will be called from an asp page. The dll itself uses the wininet api to pull an image off of another site via http. The problem (I think!) is that we are retrieving the file using InternetReadFile into a string. The string seems to be corrupting the binary data. How do you retrieve binary data (I guess using a byte array) via the wininet api in VB?

    Thanks for any help you can give.

  2. #2

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Location
    New York
    Posts
    2

    Smile The answer

    For those of you interested, the problem seemed to be caused by VB's inherent UNICODE handling of strings. The internetreadfile api call returns the binary information into a unicode string (where all those null characters are ignored, I guess). The answer was to convert the string to ANSI via the StrConv(UnicodeResultString, vbFromUnicode) function. An example:

    While bDoLoop
    sReadBuffer = vbNullString
    bDoLoop = InternetReadFile(hHttpOpenRequest, sReadBuffer, Len(sReadBuffer), lNumberOfBytesRead)
    sBuffer = sBuffer & Left$(sReadBuffer, lNumberOfBytesRead)
    If Not CBool(lNumberOfBytesRead) Then bDoLoop = False
    Wend
    InternetCloseHandle (hInternetSession)
    Dim x As Integer
    sResult = StrConv(sBuffer, vbFromUnicode)


    sResult in this case is a variant. You can then write this to a binary file or response.binarywrite via a byte array.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width