title: Why is URLDownloadToFile() not downloading my file?
body: <p>So I am trying to create a function to download a file with a variable address depending on the user with a string input using <code>URLDownloadToFile()</code> however it does not seem to actually download the file to the disk. It skips <code>S_OK</code>, <code>E_OUTOFMEMORY</code> and <code>INET_E_DOWNLOAD_FAILURE</code> to <code>UNKNOWN_ERROR</code>. Using <code>GetLastError()</code> returns <code>2</code>, checking up online said that meant <code>"Not Found"</code>. I'm not sure whether this was the website I was using or not (it's my own server with Node.JS using <code>res.download(path, filename)</code>). Hope for help, the code is below.</p>
  
  <p>Just a note, everything is properly included as needed and the process (safely) runs with <code>SE_DEBUG_NAME</code> so it hopefully should not be a permission error.</p>
  
  <pre><code>// Convert String To Wide String
  wstring S2WS(const string&amp; str) {
      int length;
      int slength = (int)str.length() + 1;
      length = MultiByteToWideChar(CP_ACP, 0, str.c_str(), slength, 0, 0);
      wchar_t* buffer = new wchar_t[length];
      MultiByteToWideChar(CP_ACP, 0, str.c_str(), slength, buffer, length);
      wstring out(buffer);
      delete[] buffer;
      return out;
  }
  
  // Download File
  int download(string url) {
      wstring wUrl = S2WS(url);
      LPCWSTR lUrl = wUrl.c_str();
      TCHAR path[MAX_PATH];
      GetCurrentDirectory(MAX_PATH, path);
      HRESULT response = URLDownloadToFile(NULL, lUrl, path, 0, NULL);
      if (response == S_OK) {
          cout &lt;&lt; "S_OK" &lt;&lt; endl;
      } else if (response == E_OUTOFMEMORY) {
          cout &lt;&lt; "E_OUTOFMEMORY" &lt;&lt; endl;
      } else if (response == INET_E_DOWNLOAD_FAILURE) {
          cout &lt;&lt; "INET_E_DOWNLOAD_FAILURE" &lt;&lt; endl;
      } else {
          cout &lt;&lt; "UNKNOWN_ERROR" &lt;&lt; endl;
      }
      return 0;
  }
  
  // Example Usage
  int main() {
      download("http://somewebsite.com/files/textfile.txt");
  }
  </code></pre>