TCHAR issue
-
In Win32 C++ how to convert
TCHAR* to LPCTSTR
TCHAR to LPTSTRPlease help...:confused::confused:
gold
What do you mean by convert?
TCHAR*
is merely a pointer to achar
orwchar_t
depending on the definition ofUNICODE
.LPCTSTR
is a typedef toconst TCHAR*
so no conversion is necessary; but you may need a cast to satisfy the compiler.TCHAR
is a single character so cannot be converted or cast toLPTSTR
; if you actually meantTCHAR*
then both expressions evaluate to the same thing: a pointer to a character or wide character.Just say 'NO' to evaluated arguments for diadic functions! Ash
-
What do you mean by convert?
TCHAR*
is merely a pointer to achar
orwchar_t
depending on the definition ofUNICODE
.LPCTSTR
is a typedef toconst TCHAR*
so no conversion is necessary; but you may need a cast to satisfy the compiler.TCHAR
is a single character so cannot be converted or cast toLPTSTR
; if you actually meantTCHAR*
then both expressions evaluate to the same thing: a pointer to a character or wide character.Just say 'NO' to evaluated arguments for diadic functions! Ash
Thanx, my one doubt is cleared, about TCHAR to LPTSTR My Program deals with UNICODE only a small example will very helpfull for me, of how to convert TCHAR* to LPCTSTR and LPTSTR. Thanx in advance.
gold
-
In Win32 C++ how to convert
TCHAR* to LPCTSTR
TCHAR to LPTSTRPlease help...:confused::confused:
gold
TCHAR* to LPCTSTR is a simple typecast
TCHAR* pch;
LPCTSTR pcch = (LPCTSTR)pch;TCHAR to LPTSTR is an address of operator
TCHAR ch;
LPTSTR pch = &ch; -
Thanx, my one doubt is cleared, about TCHAR to LPTSTR My Program deals with UNICODE only a small example will very helpfull for me, of how to convert TCHAR* to LPCTSTR and LPTSTR. Thanx in advance.
gold
goldenrose9 wrote:
a small example will very helpfull for me, of how to convert TCHAR* to LPCTSTR and LPTSTR.
There is no conversion involved; as I said in my previous post
TCHAR*
andLPTSTR
equate to the same thing, a pointer to a string (character array).LPCTSTR
is the same asconst TCHAR*
, a pointer to a string constant.Just say 'NO' to evaluated arguments for diadic functions! Ash
-
TCHAR* to LPCTSTR is a simple typecast
TCHAR* pch;
LPCTSTR pcch = (LPCTSTR)pch;TCHAR to LPTSTR is an address of operator
TCHAR ch;
LPTSTR pch = &ch;LPTSTR __stdcall gHelp(TCHAR value)
{
LPTSTR pch;
pch = &value;
return pch;
}compiler gives warning
warning C4090: 'return' : different 'const' qualifiersgold
-
In Win32 C++ how to convert
TCHAR* to LPCTSTR
TCHAR to LPTSTRPlease help...:confused::confused:
gold
Here[^] is an excellent article explaining everything you need to understand C++ strings.
Cédric Moonen Software developer
Charting control [v3.0] OpenGL game tutorial in C++ -
LPTSTR __stdcall gHelp(TCHAR value)
{
LPTSTR pch;
pch = &value;
return pch;
}compiler gives warning
warning C4090: 'return' : different 'const' qualifiersgold
You will also have a problem that you are returning a
TCHAR*
to aTCHAR
value, not an array (i.e. string). Do not do this or you will end up with memory overwrites and/or invalid data. As to your compiler warning, you must have a definition of gHelp which reads something like:LPCTSTR __stdcall gHelp(TCHAR value);
Just say 'NO' to evaluated arguments for diadic functions! Ash
-
In Win32 C++ how to convert
TCHAR* to LPCTSTR
TCHAR to LPTSTRPlease help...:confused::confused:
gold
goldenrose9 wrote:
TCHAR* to LPCTSTR
Usually, no conversion needed. If a function is promising you that it won't modify the contents (thereby expecting an
LPCTSTR
), you can still pass on a normalTCHAR*
to it.goldenrose9 wrote:
TCHAR to LPTSTR
That makes absolutely no sense.
TCHAR
is a character (wide or not depends on the build), andLPTSTR
is a pointer to one such character. How can you convert one to another?!It was ever thus, the Neophiles will always rush out and get 'The Latest Thing' at a high price and with all the inherent faults - Dalek Dave.
-
goldenrose9 wrote:
TCHAR* to LPCTSTR
Usually, no conversion needed. If a function is promising you that it won't modify the contents (thereby expecting an
LPCTSTR
), you can still pass on a normalTCHAR*
to it.goldenrose9 wrote:
TCHAR to LPTSTR
That makes absolutely no sense.
TCHAR
is a character (wide or not depends on the build), andLPTSTR
is a pointer to one such character. How can you convert one to another?!It was ever thus, the Neophiles will always rush out and get 'The Latest Thing' at a high price and with all the inherent faults - Dalek Dave.
thanx a lot.
gold
-
LPTSTR __stdcall gHelp(TCHAR value)
{
LPTSTR pch;
pch = &value;
return pch;
}compiler gives warning
warning C4090: 'return' : different 'const' qualifiersgold
This won't work. You are passing the TCHAR variable by value, so the parameter value is just a temporary local copy, and the address of it will be invalidated upon return! Pass the TCHAR parameter by reference instead, like this:
LPTSTR __stdcall gHelp(TCHAR& value)
...