Click here to Skip to main content
11,631,906 members (68,973 online)
Click here to Skip to main content

Tagged as

Converting TCHAR[] to string, while getting PC Name

, 8 Jun 2010 CPOL 4.1K 1
Rate this:
Please Sign up or sign in to vote.
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

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Alain Rist
France France
No Biography provided

You may also be interested in...

Comments and Discussions

 
GeneralSee the allowed characters for lpComputerName in MSDN: http:... Pin
Alain Rist29-Jul-10 11:00
memberAlain Rist29-Jul-10 11:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150728.1 | Last Updated 9 Jun 2010
Article Copyright 2010 by Alain Rist
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid