Link to home
Start Free TrialLog in
Avatar of joeshmo
joeshmo

asked on

Downloading from web page: status callback

My question is a simple one.  How can I get the "!" point to be displayed in the OnStatusCallback function?  I would think that the "!" would be printed a bunch before the code was displayed.  The ! is not displayed at all.

// Global functions
CString Read (CHttpFile *file);

// Classes
class CInternetSession2 : public CInternetSession
{ void OnStatusCallback (DWORD dwContext, DWORD dwInternetStatus, LPVOID lpvStatusInformation, DWORD dwStatusInformationLength);
};

void CInternetSession2::OnStatusCallback (DWORD dwContext, DWORD dwInternetStatus, LPVOID lpvStatusInformation, DWORD dwStatusInformationLength)
{ printf ("\r\n\r\n!\r\n\r\n"); // Doesn't display this, ever.
}

int _tmain (int argc, TCHAR* argv[], TCHAR* envp[])
{ if (!AfxWinInit (::GetModuleHandle (NULL), NULL, ::GetCommandLine (), 0))
  { printf ("Fatal Error: MFC initialization failed.");
    return 1;
  }

  CInternetSession2 session;
  CHttpFile *file;

  file = (CHttpFile *) session.OpenURL ("http://etc", 1);

  CString data = Read (file);
  printf (data);

  session.Close ();

  return 0;
}

// Reads all data from a CHttpFile, and then closes and deletes the file.
CString Read (CHttpFile *file)
{ CString ret;

  char data[2];
  int numbytes;

  for (;;)
  { memset (data, 0, 2);

    numbytes = file->Read (data, 1);
    data[numbytes] = 0; // VERY important.
    ret += data;

    if (numbytes == 0)
    { break; }
  }

  file->Close ();
  delete file;

  return ret;
}
Avatar of jhance
jhance

Are you sure that CInternetSession2::OnStatusCallback is even getting called?
Avatar of joeshmo

ASKER

That's probably part of the question.  I strongly doubt it's even being called.  The code for the web pages print out to the screen without a problem.  There are no exclamation marks however.

Why isn't it being called?  How can I get it to be called?
ASKER CERTIFIED SOLUTION
Avatar of jhance
jhance

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of joeshmo

ASKER

That was what the problem was.  I must have forgotten to add it because I knew it was necessary.  Oops.  Thanks for your help!