DeepForge-Tech / DeepForge-Toolset

DeepForge Toolset - cross-platform installer of necessary tools for programming.
GNU General Public License v3.0
3 stars 2 forks source link

Пример скачивания исходников приложения с сайта на windows #20

Closed Blackflame576 closed 1 year ago

Blackflame576 commented 1 year ago
#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;
}