CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2010
    Posts
    75

    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?

  2. #2
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: Can't get InternetReadFile to work

    Quote Originally Posted by paprica View Post
    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...

  3. #3
    Join Date
    Jul 2010
    Posts
    75

    Re: Can't get InternetReadFile to work

    You're right. Thanks!
    Code:
    InternetReadFile(m_hOpenURL, &buf, 1, &dwRead)

  4. #4
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    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
  •  





Click Here to Expand Forum to Full Width

Featured