#pragma comment(lib, "Urlmon.lib") //urlmon library for the URL Open Blocking Stream function
#include <urlmon.h>
#include <cstdio>
#include <iostream> //Headers for String Operations
#include <string>
using namespace std;
int main()
{
//WIndows IStream interface
IStream* stream;
//Source URL
const char* URL = "http://facebook.com";
// URLDownloadToFile returns S_OK on success
if (S_OK != URLOpenBlockingStreamA(0, URL, &stream, 0, 0))
{
cout << "Failed."; //Return On Failure
return -1;
}
char buff[100]; //char buffer to repeatedly get data from the stream.
string s;
unsigned long bytesRead;
while(true) {
stream -> Read(buff,100,&bytesRead); //It Read the data till available
if(0U == bytesRead) // bytesRead are zero when end of file reached.
{
break;
}
s.append(buff, bytesRead); //append and collect to the string.
};
stream -> Release(); //Realease the interface.
cout << s << endl;
return 0;
}