Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LPTSTR and LPCSTR C++

Tags:

c++

lpcstr

lptstr

So the output of the function GetUserName() gives the username as a LPTSTR. I need to convert this to a LPCSTR, as I want the username to be the name of the an ftpdirectory.

TCHAR id [UNLEN+1];
DWORD size = UNLEN+1;
GetUserName(id, &size); // this is an LPTSTR

FtpCreateDirectory(hFtpSession,id) // 2d parameter should be an LPCSTR

The problem is that I need to convert the LPTSTR string to a LPCSTR string. Now I know that:

LPTSTR is a (non-const) TCHAR string and LPCSTR is a const string.

But how do I convert a TCHAR to a const string?

I should note I don't have a rich programming/C++ background, I should also note that I'm compiling in multi-byte, not unicode.

like image 395
Rob Avatar asked May 12 '12 16:05

Rob


1 Answers

As you are compiling for multi-byte, not unicode you don't have to do anything. LPTSTR will convert implicitly to LPCSTR as it's just a char* to const char* conversion.

like image 123
CB Bailey Avatar answered Oct 06 '22 02:10

CB Bailey