#include "stdafx.h"
#include <windows.h>
#include <tlhelp32.h>
#include <tchar.h>
#include <iostream>
#include <UrlMon.h>
#include <cstring>
#pragma comment(lib, "UrlMon.lib")
using namespace std;
int main()
{
char* appdata = getenv("APPDATA"); //Gets %Appdata% path
char* truepath = strcat(appdata, "\\USR\\file.dat"); // file location
cout << truepath ;
HRESULT hr = URLDownloadToFile(NULL, _T("http://localhost:8080/upload.php?name=Huh?" + truepath), _T("d"), 0, NULL);
cin.get();
return 0;
}
This is my code above, and I am getting an error on this lane:
HRESULT hr = URLDownloadToFile(NULL, _T("http://localhost:8080/upload.php?name=Huh?" + truepath), _T("d"), 0, NULL);
The compilation error it's giving me says that "+ truepath" is not possible to be used there.
I've tried .c_str() and few other ways but can't manage it to work. Any help is appreciated.
// ANSI Build
std::string appdata( getenv("APPDATA") );
appdata += "\\USR\\file.dat";
std::string url( "http://localhost:8080/upload.php?name=Huh?" );
url += appdata;
URLDownloadToFile( NULL, url.c_str(), [...]
// UNICODE Build
std::wstring appdata( _wgetenv( L"APPDATA" ) );
appdata += L"\\USR\\file.dat";
std::wstring url( L"http://localhost:8080/upload.php?name=Huh?" );
url += appdata;
URLDownloadToFile( NULL, url.c_str(), [...]