title: Downloading data via WinInet
body: <p>And so there is a code, that can download data with size not higher than 1024*100 bytes. Code brought from <a href="https://rsdn.org/article/inet/inetapi.xml" rel="nofollow noreferrer">https://rsdn.org/article/inet/inetapi.xml</a>.</p>
  
  <p>As far as I understand, <code>InternetReadFile</code> after every call should move on the read characters count, or it's sensless, because it'll return the same data. I red, that there is a function,that moves reading start pointer. Have I to use it?</p>
  
  <pre><code>HINTERNET hInternetSession;
  HINTERNET hURL;
  char cBuffer[1024*100];            // I'm only going to access 1K of info.
  BOOL bResult;
  DWORD dwBytesRead;
  
  // Make internet connection.
  hInternetSession = InternetOpen(
      L"tes", // agent
      INTERNET_OPEN_TYPE_PRECONFIG,  // access
      NULL, NULL, 0);                // defaults
  
  // Make connection to desired page.
  hURL = InternetOpenUrl(
      hInternetSession,                       // session handle
      L"https://www.google.com.ua/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png",  // URL to access
      NULL, 0, 0, 0);                         // defaults
  
  // Read page into memory buffer.
  while(bResult = InternetReadFile(
      hURL,              // handle to URL
      (LPSTR)cBuffer,    // pointer to buffer
      (DWORD)1024 * 100,       // size of buffer
      &amp;dwBytesRead)==TRUE&amp;&amp;dwBytesRead&gt;0) // pointer to var to hold return value
  
  // Close down connections.
  InternetCloseHandle(hURL);
  InternetCloseHandle(hInternetSession);
  
  DWORD dwTemp;
  HANDLE hFile = CreateFile(L"googlelogo_color_272x92dp.png", GENERIC_WRITE, 0, NULL,
      CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
  if (INVALID_HANDLE_VALUE == hFile) {
      return 0;
  }
  WriteFile(hFile, cBuffer, sizeof(cBuffer), &amp;dwTemp, NULL);
  </code></pre>
  
  <p><strong>Issue: I can't read more than 1024*1024 bytes, program crashes, when creates char[1024*1024]</strong></p>