0

I'm trying to download a file to

 char* appdata = getenv("APPDATA");
lpURLDownloadToFile URLDownloadToFile;
HMODULE hUrlmon = LoadLibrary("URLMON.DLL");
URLDownloadToFile = (lpURLDownloadToFile)GetProcAddress(hUrlmon, "URLDownloadToFileA");
URLDownloadToFile(0, "http://example.com/test.zip",appdata+"test.zip", 0, 0); 

I don't have an error when I write the path manually,But ı got error when I try to use appdata+"test.zip"

How can I do it. Thanks.

adalwin
  • 1
  • 1

1 Answers1

0

You cannot combine char* pointers by adding them like so, you need to concatenate those strings. You might want to use std:string instead which support operator+=.

std::string appdata(getenv("APPDATA"));
appdata += "test.zip";

HMODULE hUrlmon = LoadLibrary("URLMON.DLL");
URLDownloadToFile = (lpURLDownloadToFile)GetProcAddress(hUrlmon, "URLDownloadToFileA");
URLDownloadToFile(0, "http://example.com/test.zip", appdata.c_str(), 0, 0); 
Eric Fortin
  • 7,533
  • 2
  • 25
  • 33