Note that there are some explanatory texts on larger screens.

plurals
  1. POWinINet trouble downloading file to client?
    primarykey
    data
    text
    <p>I'm curious why I'm having trouble with this function. I'm downloading a PNG file on the web to a destination path. For example, downloading the Google image to the C: drive:</p> <p>netDownloadData("<a href="http://www.google.com/intl/en_ALL/images/srpr/logo1w.png" rel="nofollow noreferrer">http://www.google.com/intl/en_ALL/images/srpr/logo1w.png</a>", "c:\file.png");</p> <p>The file size is correct after downloading. Nothing returning false. When I try opening it it won't show the image. Any ideas are helpful. Thanks!</p> <p>Here's the code: </p> <pre><code>bool netDownloadData(const char *strSourceUrl, const char *strDestPath) { HINTERNET hINet = NULL; HINTERNET hFile = NULL; char buffer[1024]; DWORD dwRead; String sTemp; FILE *fp = NULL; DWORD size = 0; // Open a new internet session hINet = netInit(); if (hINet == NULL) { sprintf(buffer, "Initializing WinINet failed.", strSourceUrl); utilLog(buffer); netCloseHandle(hINet); return false; } // Open the requested url. hFile = netOpenUrl(hINet, strSourceUrl); if (hFile == NULL) { sprintf(buffer, "URL failed upon loading: %s\n", strSourceUrl); utilLog(buffer); netCloseHandle(hINet); return false; } // Read file. while (InternetReadFile(hFile, buffer, 1023, &amp;dwRead)) { if (dwRead == 0) break; buffer[dwRead] = 0; sTemp += buffer; size += dwRead; } // Load information to file. fp = fopen(strDestPath, "wb"); if (fp == NULL) return false; fwrite(sTemp, size, 1, fp); fclose(fp); InternetCloseHandle(hFile); InternetCloseHandle(hINet); return true; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload