-
July 20th, 2011, 10:48 AM
#1
Can't get InternetReadFile to work
Hello, here's my code:
Code:
std::string ReadHTML()
{
BYTE buf = 0;
DWORD dwRead;
std::string s = "";
while(InternetReadFile(m_hOpenURL, reinterpret_cast<LPVOID>(buf), 1, &dwRead) == TRUE)
{
if(dwRead == 0)
break;
s += buf;
}
return s;
}
What am I doing wrong?
-
July 20th, 2011, 11:23 AM
#2
Re: Can't get InternetReadFile to work
Originally Posted by paprica
Code:
std::string ReadHTML()
{
BYTE buf = 0;
DWORD dwRead;
while(InternetReadFile(m_hOpenURL, reinterpret_cast<LPVOID>(buf), 1, &dwRead) == TRUE)
{
}
What am I doing wrong?
The second parameter should be "Pointer to a buffer that receives the data."
You pass a value of 0, forcefully casted to LPVOID.
My guess is - access violation writing to 0x00000000.
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
July 20th, 2011, 11:27 AM
#3
Re: Can't get InternetReadFile to work
You're right. Thanks!
Code:
InternetReadFile(m_hOpenURL, &buf, 1, &dwRead)
-
July 21st, 2011, 01:04 AM
#4
Re: Can't get InternetReadFile to work
The snipped is from a real code:
Code:
TCHAR buf[4096];
DWORD dwRead = 0;
while( ::InternetReadFile( hInetUrl, buf, sizeof(buf), &dwRead ) && (dwRead != 0) )
{
DWORD dwWritten = 0;
if( ::WriteFile( hFile, buf, dwRead, &dwWritten, NULL ) )
{
ATLASSERT( dwRead == dwWritten );
qwYield += dwRead;
PutYield( qwYield );
if( qwTotal && (QWORD(-1) != qwTotal) )
{
// move progress safely
PutProgress( 100 * DOUBLE(qwYield)/qwTotal );
}
}
else
{
throw(ERR_TARGET_WRITE_FAIL); // write file failed
}
}
Best regards,
Igor
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|