You cannot use _T()
like this. It's a macro that applies the L
suffix to string literals, not a function that can be applied to arbitrary expressions.
You should start with the wide-string versions of those library types, which is essentially the equivalent of what you are trying to hack in with the _T()
:
std::wifstream
std::wofstream
std::wstring
It also seems likely, as you are calling a Windows API function, that you will have to obtain a pointer to the string data rather than trying to pass an actual C++ string object.
getStringFromFile().c_str()
This'll give you the wchar_t const*
that you need though, to be honest, I'm not entirely sure whether it's safe to do this with a temporary. It depends on what the preconditions are for CreateWindowEx
.
Safest approach, IMO:
std::wstring getStringFromFile()
{
std::wifstream in("in.txt");
std::wofstream out("out.txt");
std::wstring line;
while (std::getline(in,line)) {
if (line.empty())
line = "http://www.google.com/";
}
return line;
}
// ...
const std::wstring str = getStringFromFile();
CreateWindowEx(0, _T("EDIT"),
str.c_str(),
WS_CHILD | WS_VISIBLE | WS_BORDER,
260, 10,
200, 20,
hWnd, NULL, hInst, NULL
);
As a further complication, the _T()
macro only applies the L
suffix to string literals when your program has UNICODE
defined. If you wish to support both Unicode and non-Unicode modes, you'll need to switch back to the original std::string
etc when UNICODE
is not defined. That being said, I've been led to believe that disabling UNICODE
is rare nowadays. Still, I'm no Windows dev…