Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

reading image files into a string buffer(since API function supports only string

Hai all,

im back with another problem!

I am using a API function which accepts data only into a string buffer. (InternetReadFile function in WinINet API).

I tried reading a JPG file from the cache and then writing it out again to disk. I didnt get back a JPG image.

So how do we work around the fact that InternetReadFile reads into a string buffer, but I need the data in a Byte() array, so that I can write back the JPG file properly to disk??

converting each character in the string to Bytes returned an error..

'Buffer is the string and data is the Byte()
For i = 1 To Len(Buffer)
data(i)= CByte(Mid(Buffer, i, 1))
Next


sorry if im missing something!

thanks for ur time..

Pradeep V
[806 byte] By [deeps_chennai] at [2007-11-11 7:00:30]
# 1 Re: reading image files into a string buffer(since API function supports only string
hello folks,

sorry but the function DOES accept a byte array. it was pointed out in another forum.

However, I have a problem using the byte array..

When I use a byte array, all i get in the output is 0s.

When i use a string array, i got the proper output.

Heres the code..

Private Sub Form_Load()

Const BYTELEN As Integer = 1024
Dim bytes() As Byte

url= "http://somesite.com/somepage.html"

ReDim bytes(BYTELEN)

'Reading data from the cache..

hOpen = InternetOpen(UserAgent, INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, INTERNET_FLAG_FROM_CACHE)

hFile = InternetOpenUrl(hOpen, url, vbNullString, ByVal 0&, &O0, ByVal 0&)

Call InternetReadFile(hFile, bytes, BYTELEN, bytesRead)

For counter = 0 To bytesRead-1
Debug.Print bytes(counter)
Next

End Sub



What could be the problem.. thanks for ur time.

regards,

Pradeep V
deeps_chennai at 2007-11-11 17:27:40 >