convert LPTSTR to string

user2407956 picture user2407956 · May 22, 2013 · Viewed 16.4k times · Source

I am getting text from a Window and it returns in LPTSTR. I have to turn it into string or else I have to rewrite a lot of my code. Also What is a LPTSTR and how is it different from a string?

Answer

tay10r picture tay10r · May 22, 2013

LPTSTR is a string, it's just not constant.

You can use it like a regular char * if as long as you don't define UNICODE in your application. The difference between a unicode and normal string is the length of the character. In unicode it is either 2 or 4 and in standard programs it is 1 byte.

As some people might point out, you're not the only one to ask this question. This is usually a topic of confusion for people learning to program in the Windows environment. See this for some clarification, from MSDN. I'd also recommend viewing their desktop API reference for a lot of useful information that may help you with future inquiries.