Okay, so I have been trying to do some simple stuff like downloading and transferring files in Visual C++, and I had been using the URLDownloadToFile()
function. The code compiled, and it didn't give any errors, however it would not download anything. Obviously, I didn't just run over here the minute my code doesn't work, so I did some debugging and such, which I will mention in a minute. Here's the code.
#pragma comment(lib, "urlmon.lib")
#include <Windows.h>
#include <urlmon.h>
#include <stdio.h>
#include <tchar.h>
#include <string>
using namespace std;
void dwfile();
int main() {
dwfile();
return 0;
}
int dwfile() {
string url("http://0.0.0.0/putty.exe"); // I changed the IP for privacy
string file("C:\\Putty");
const char *strUrl = url.c_str();
const char *strFile = file.c_str(); // I had been testing with these, not currently using them
HRESULT hr = URLDownloadToFile(NULL, url.c_str(), file.c_str(), 0, NULL);
if (FAILED(hr)) {
printf("failed\n");
OutputDebugString("\n");
OutputDebugString("FAILED\n");
OutputDebugString("\n");
GetLastError();
system("pause");
}
}
Keep in mind that I am not a professional, and that I am not incredibly experienced in C++. I read a few books, but I am on the younger side, and I am currently doing this for fun.
As for debugging, url
and file
would throw errors when called in the URlDownloadToFunction
until I did .c_str()
and converted them. I set a break point at the function call, and noticed that the variable hr had the value of 0xcccccccc, until the next break point, at the printf
statement, when hr
then had the value of E_ABORT Operation Aborted
and nothing else. There didn't seem to be an issue with the strings, but it didn't tell me anything else. I'm honestly just stumped. Any and all help is appreciated greatly.
EDIT
I feel like an idiot, but I was trying to write to the root of my C:\ drive, even though I had forgot to enable UAC. When I enabled it, it downloaded and ran Putty just fine, although I'm considering changing from URLDownloadToFile() to using WinInet. Thanks for all the help!