// 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(), [...]
Not able to use char* with URLDownloadToFile
Question
#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.
Solution
OTHER TIPS
You cannot add two pointers.
The truepath
is a pointer to char.
And when you say "http://localhost:8080/upload.php?name=Huh?"
it returns a pointer to a char
. So, you are trying to add two pointer and here is what standard says about the additive operator...
5.7
For addition, either both operands shall have arithmetic or unscoped enumeration
type, or one operand shall be a pointer to a completely-defined object
type and the other shall have integral or unscoped enumeration type.
Also, you have to allocate memory for the truepath
variable or else it will crash.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow