PDA

Click to See Complete Forum and Search --> : WinInet API Binary D/L


dneigler
Oct 13th, 2000, 12:23 PM
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.

dneigler
Oct 16th, 2000, 11:12 AM
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.