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.
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.