Converting TCHAR[] to string, while getting PC Name






4.67/5 (3 votes)
You might have considered using ::GetComputerNameA() which does the conversion for you:std::string GetSystemName(){ CHAR sBuf[MAX_COMPUTERNAME_LENGTH + 1] = {0}; DWORD dwLen = MAX_COMPUTERNAME_LENGTH; ::GetComputerNameA(sBuf, &dwLen); return std::string(sBuf);}Note...
You might have considered using
::GetComputerNameA()
which does the conversion for you:
std::string GetSystemName() { CHAR sBuf[MAX_COMPUTERNAME_LENGTH + 1] = {0}; DWORD dwLen = MAX_COMPUTERNAME_LENGTH; ::GetComputerNameA(sBuf, &dwLen); return std::string(sBuf); }Note that you can do the same for any system function with a xxxA version. cheers, AR