Did you actually try anything?
const QString name
("COMPUTERNAME");
// Via a std::wstring
WCHAR result1[128];
std::wstring s = name.toStdWString();
DWORD len = GetEnvironmentVariable(s.c_str(), result1, 128);
qDebug
() <<
QString::fromWCharArray(result1
);
// Via a buffer
WCHAR result2[128];
wchar_t buf[name.length() + 1];
int l = name.toWCharArray(buf);
buf[l] = 0;
len = GetEnvironmentVariable(buf, result2, 128);
qDebug
() <<
QString::fromWCharArray(result2
);
// Using utf16()
WCHAR result3[128];
len = GetEnvironmentVariable(reinterpret_cast<LPCTSTR>(name.utf16()), result3, 128);
qDebug
() <<
QString::fromWCharArray(result3
);
const QString name("COMPUTERNAME");
// Via a std::wstring
WCHAR result1[128];
std::wstring s = name.toStdWString();
DWORD len = GetEnvironmentVariable(s.c_str(), result1, 128);
qDebug() << QString::fromWCharArray(result1);
// Via a buffer
WCHAR result2[128];
wchar_t buf[name.length() + 1];
int l = name.toWCharArray(buf);
buf[l] = 0;
len = GetEnvironmentVariable(buf, result2, 128);
qDebug() << QString::fromWCharArray(result2);
// Using utf16()
WCHAR result3[128];
len = GetEnvironmentVariable(reinterpret_cast<LPCTSTR>(name.utf16()), result3, 128);
qDebug() << QString::fromWCharArray(result3);
To copy to clipboard, switch view to plain text mode
Bookmarks