| CodeGuru Home | VC++ / MFC / C++ | .NET / C# | Visual Basic | Newsletters | VB Forums | Developer.com |
|
|||||||
| Visual C++ Programming Ask questions about Windows programming with Visual C++ and help others by answering their questions. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
TCHAR [] and LPCTSTR
could someone help me on the following?
TCHAR name[50]; CString str="test"; name=(LPCTSTR)str; The above produce compile error error C2440: '=' : cannot convert from 'const unsigned short *' I don't want Any good fix for the above? |
|
#2
|
|||
|
|||
|
Declaring a string literal automatically allocates the memory necessary
'LPTSTR' and 'LPCTSTR' are just types for arbitrary pointers. No memory is allocated in their use. Rewrite the code like this. Code:
LPTSTR name; CString str="test"; name=(LPTSTR)str; |
|
#3
|
|||
|
|||
|
yes.. i forgot about one thing just now,
i should be able Code:
LPTSTR name; CString str="test"; name=(LPTSTR)str; where memberStruct has a name data type char[50]. something like this: MEMBERSTRUCT { .... char name[50]; ..... } Code:
GetInfo(LPTSTR name)
{
MemberStruct member;
SomebodyFucntion(&member);
//now i need
|
|
#4
|
||||
|
||||
|
Looks like you are compiling this program in Unicode, so your LPSTR will actually be an array of unsigned shorts (2 bytes) while your char name[50] is just an array of single bytes.
There are two solutions : 1) Convert the Unicode string (the LPSTR) 2) use an array of unsigned shorts in your struct MEMBERSTRUCT I guess what you would like
__________________
Get this small utility to do basic syntax highlighting in vBulletin forums (like Codeguru) easily. Supports C++ and VB out of the box, but can be configured for other languages. |
|
#5
|
|||
|
|||
|
I am compiling for unicode, yes..
![]() yes i would go for option 2, but what if memberStruct is 3rd party struct.(i couldn;t change anything on that) |
|
#6
|
|||
|
|||
|
I just want
Inside this fucntion, on one hand, i have name=(LPCTSTR)FoundResult; On the other hand, i need so i need |
|
#7
|
|||
|
|||
|
Quote:
Code:
TCHAR name[50]; CString str="test"; wcscpy(name, str); |
|
#8
|
|||
|
|||
|
So
Code:
void GetInfo(LPTSTR name) {
CString str=name;
str=T("Info"); // Replace with your string manipulation and such
wcscpy(name, str);
}
|
|
#9
|
||||
|
||||
|
Code:
BSTR unicodestr; unicodestr = SysAllocStringLen(NULL, lstrlenA(ansistr) * 2); MultiByteToWideChar(CODE_PAGE, 0, ansistr, -1, unicodestr, lstrlenA(ansistr)); Code:
char *szString; szString = (char *) malloc(SysStringLen(unicodestr) + 1); WideCharToMultiByte(CODE_PAGE, 0, unicodestr, -1, ansistr, SysStringLen(unicodestr), NULL, NULL); |
![]() |
| Bookmarks |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|