0
string pagexx = "http://website.com/" + chatname;
string pathxx = "test";
HRESULT resxx = URLDownloadToFile (NULL, _T(pagexx.c_str()),_T(pathxx.c_str()), 0, NULL );

The error is "Error: identifier "Lpagexx" is undefined." and same with pathxx

I cant just enter the string like _T("nice") because I need chatname in it specifically. how can I make this work?

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
  • Try `wstring` instead. Or look up wide character strings vs regular strings. or turn off Unicode in your complier settings. – Chubosaurus Software Jun 13 '15 at 08:20
  • 2
    for your next questions I advise you to create a minimal, complete, and verifiable example (explained here: http://stackoverflow.com/help/mcve ) to enable people to help you with your problem – xmoex Jun 13 '15 at 08:22

3 Answers3

1

_T is a macro for putting the proper prefix on a literal. That is not what you're doing, so you don't want to use _T.

Your problem begins on the very first line, since you've hardcoded that you're using strings with narrow characters (i.e. string is a string specifically of char elements) rather than selecting the appropriate string type. See the question Automatically change between std::string and std::wstring according to unicode setting in MSVC++?.

Community
  • 1
  • 1
1

If your strings only contain non-unicode then your simplest solution is:

HRESULT resxx = URLDownloadToFileA (NULL, pagexx.c_str(), pathxx.c_str(), 0, NULL );

The _T stuff has been obsolete for a decade at least, there is no reason at all to bother with the complication of having an application compile against two different versions of Windows API.

If your std::strings contain UTF-8 then you will need to convert them to UTF-16 and then call URLDownloadToFileW.

M.M
  • 138,810
  • 21
  • 208
  • 365
0

_T is just a macro with prefixis its argument with L (if compiled with unicode). Variables must be declared using wchar_t(or wstring and simmilar)

Assuming chatname is of type wstring.

 wstring pagexx = L"http://website.com/" + chatname;
 wstring pathxx = L"test";
 HRESULT resxx = URLDownloadToFile ( NULL, pagexx.c_str(), pathxx.c_str(), 0, NULL );

Or better (since you are compiling something under Microsoft, you can use more general macros, so that you can compile same code with or without UNICODE being set).

 _tstring pagexx = _T("http://website.com/") + chatname;
 _tstring pathxx = _T("test");
 HRESULT resxx = URLDownloadToFile ( NULL, pagexx.c_str(), pathxx.c_str(), 0, NULL );
Zereges
  • 5,139
  • 1
  • 25
  • 49