Click here to Skip to main content
15,868,164 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
See more:
hi everybody. i have used TEXT() function in my code in such a way:
C++
TEXT("some text")

to convert a char* to wchar_t.
is there any way to replace the constant string to a variable?
C++
char *cAdress=NULL;
cAdress = (char *)alloca(aAdress.size() + 1);
memcpy(cAdress, aAdress.c_str(), aAdress.size() + 1);
TEXT(cAdress);
Posted

If you need to convert text from ASCII to Unicode (and vice versa) within your program then you need to use the appropriate conversion functions as described in this MSDN section[^].
 
Share this answer
 
v2
Comments
CPallini 14-Sep-13 11:44am    
5.
Richard MacCutchan 14-Sep-13 11:47am    
:thumbsup:
Sergey Alexandrovich Kryukov 14-Sep-13 21:52pm    
5ed.
—SA
Richard MacCutchan 15-Sep-13 3:37am    
Thank you.
Identifies a string as Unicode when UNICODE is defined by a preprocessor directive during compilation. Otherwise, the macro identifies a string as an ANSI string.
Please look here: http://msdn.microsoft.com/en-us/library/windows/desktop/dd374074%28v=vs.85%29.aspx[^]

A similar question has been discussed here:Convert char * to wchar*[^]
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 14-Sep-13 21:53pm    
5ed.
—SA
Volynsky Alex 15-Sep-13 15:56pm    
Thank you very much Sergey Alexandrovich!
Mojtaba Setoodeh 15-Sep-13 0:22am    
tnx Volynsky Alex. that was what i needed
Volynsky Alex 15-Sep-13 16:00pm    
I'm glad I was able to help
I think it is a MACRO, not a function.

It will convert ("identify") a string literal to unicode if the project is unicode, if the project is not unicode, the string will stay the same

Have a look at the MSDN documentation ( http://msdn.microsoft.com/en-us/library/windows/desktop/dd374074(v=vs.85).aspx)

for example, It will let you pass a normal ANSI string to a function that receives a unicode string.
 
Share this answer
 
Comments
Richard MacCutchan 14-Sep-13 9:34am    
It will let you pass a normal ANSI string to a function that receives a unicode string.
Not true, a function that expects a Unicode string will not accept an ASCII one. The TEXT macro is a compile time directive, that generates the string as ASCII or Unicode depending on preprocessor directives.
Maximilien 14-Sep-13 12:01pm    
Thanks, I stand corrected! :-) will edit my answer to redirect it to yours!
CPallini 14-Sep-13 11:46am    
Richard is right, I think your last sentence is a bit unfortunate.

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