Click here to Skip to main content
15,921,113 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,
What is difference between CStringW and lptstr
or
between CStringA and lpstr?
sorry, I know this question is very simple and basic but please answer.
Thanks
Posted
Comments
pasztorpisti 12-Oct-13 14:56pm    
You won't understand the real purpose of these types without understanding encoding (like windows1252, utf8, utf16, shift-jis, ...) of (unicode) text first.
Hanoi 2014 13-Oct-13 1:03am    
I know all of this, I can't understand where to use them in type casting. this is my problem.
pasztorpisti 13-Oct-13 8:51am    
If you know encodings and basic C/C++ programming then you wouldn't be here with these questions.

CString is a class (MFC/ATL) that handles character data (strings). The A version is restricted to ASCII characters (8 bit), while the W version handles Unicode (16 bit). LPTSTR is a Windows definition for TCHAR* which is a pointer to a character string. The T types will be generated as ASCII or Unicode depending on the compiler settings. LPSTR is a Windows definition for char* and is ASCII only.
 
Share this answer
 
Comments
Hanoi 2014 13-Oct-13 1:03am    
I know all of this, but I can't use them in type casting.
Richard MacCutchan 13-Oct-13 5:47am    
That all depends on what you are trying to do. You can cast a CString to an LPTSTR or an LPSTR, as appropriate, since that is handled by operator overloading. You cannot cast in the other direction, as casting from a pointer to an object makes no sense.
Hanoi 2014 13-Oct-13 5:59am    
struct userdata
{
char sUserName[20];
char sMsg[1000];
};

CString sUserName;
sUserName.Format(L"%S : %S", udata->strUserName,udata->strMsg);
it gives <badptr>
sometimes it works but sometimes doesn't.
I don't know where is my problem?
Richard MacCutchan 13-Oct-13 6:27am    
sometimes it works but sometimes doesn't.
I don't think anyone else would be able to guess either with that little information.
Hanoi 2014 13-Oct-13 6:38am    
OK, Thanks I think my problem is about basic topic.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900