简体   繁体   English

C ++将文件下载到appdata

[英]C++ Downloading a file to appdata

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" 手动编写路径时没有错误,但是尝试使用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. 您不能像这样添加char*指针来组合它们,您需要连接这些字符串。 You might want to use std:string instead which support operator+= . 您可能想使用std:string代替它,它支持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); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM