Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting data from Internet 1

Status
Not open for further replies.

PavelGur

Programmer
Sep 21, 2001
75
0
0
I have the same program on two computers that gets data from Internet. It is using the following code to do it:

<code>
if (hSession)
{
hURL = ::InternetOpenUrl(
hSession,
szURL,
NULL,
NULL,
INTERNET_FLAG_DONT_CACHE,
NULL
);
if (hURL)
bFile = ::InternetReadFile(
hURL,
&szHTML,
0xFFFF,
&dwBytesRead
);
}
</code>
I'm getting 20524 bytes on one computer and 1392 bytes on another reading the same URL. It's got to be a setting problem. But I can not figure out where it is.
Thank you, Pavel.
 
It's [code][/code], not <code></code>

As for the other problem, why not just print the bytes you have to see what they say. My guess is the short one is an HTML error message, say "permission denied" or something.

What type is szHTML ?
Whatever it is, I'm pretty sure that putting & in front of it is the wrong thing to do.

Like is it for example
[tt]char szHTML[0xFFFF];[/tt]

--
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
 
Salem, thanks for response. I'm sorry about <code>. I suggest a little note in front new message panel.
Yes, it is char szHTML[0xFFFF];
And as to & in front of it, it works perfectly well on one computer and does not on another.
I did print all 1392 bytes of szHTML as you advised and did not find any error messages, only truncated source code of URL's HTML.
Thanks again, Pavel.
 
Remarks
Remarks

InternetReadFile operates much like the base ReadFile function, with a few exceptions. Typically, InternetReadFile retrieves data from an HINTERNET handle as a sequential stream of bytes. The amount of data to be read for each call to InternetReadFile is specified by the dwNumberOfBytesToRead parameter and the data is returned in the lpBuffer parameter. A normal read retrieves the specified dwNumberOfBytesToRead for each call to InternetReadFile until the end of the file is reached. To ensure all data is retrieved, [red]an application must continue to call the InternetReadFile function until the function returns TRUE and the lpdwNumberOfBytesRead parameter equals zero[/red]. This is especially important if the requested data is written to the cache, because otherwise the cache will not be properly updated and the file downloaded will not be committed to the cache. Note that caching happens automatically unless the original request to open the data stream set the INTERNET_FLAG_NO_CACHE_WRITE flag.
Perhaps one machine just gets lucky and returns the whole page in one call. But I wouldn't rely on that behaviour continuing.


--
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top