From: rxgmoral on

How to LPCTSTR Convert to char *

thank :)



--
rxgmoral
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------



From: Tom Serface on
Well a lot depends on how your project was compiled. If you compiled
non-Unicode then you won't have to convert really since the "T" will already
compile as "char" rather than "wchar_t". If you are using Unicode you can
use WideCharToMultiByte() to convert.

In either case the first is a const and the second, not so you will have to
be careful how you use it. You could just assign either to a CString. If
you assign to CStringW it will convert char * to wchar_t and if you assign
to CStringA it will do the opposite. It's kind of handy, but you have to be
careful how you use it.

Tom

"rxgmoral" <rxgmoral.2idl9p(a)mail.codecomments.com> wrote in message
news:rxgmoral.2idl9p(a)mail.codecomments.com...
>
> How to LPCTSTR Convert to char *
>
> thank :)
>
>
>
> --
> rxgmoral
> ------------------------------------------------------------------------
> Posted via http://www.codecomments.com
> ------------------------------------------------------------------------
>
>
>


From: Mihai N. on
"Tom Serface" <tserface(a)msn.com> wrote in
news:uRy8wWPGHHA.1804(a)TK2MSFTNGP02.phx.gbl:

> Well a lot depends on how your project was compiled. If you compiled
> non-Unicode then you won't have to convert really since the "T" will
already
> compile as "char" rather than "wchar_t". If you are using Unicode you can
> use WideCharToMultiByte() to convert.
>
> In either case the first is a const and the second, not so you will have to
> be careful how you use it. You could just assign either to a CString. If
> you assign to CStringW it will convert char * to wchar_t and if you assign
> to CStringA it will do the opposite. It's kind of handy, but you have to
be
> careful how you use it.

Or "the easy way": T2A
(with the warning that you might loose data).


--
Mihai Nita [Microsoft MVP, Windows - SDK]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
From: Tom Serface on
Hi Mihai,

You're right. All of those macros (and there seem to be a ton of them) are
handy once you divine the mystery of their names :o) Thanks for adding the
additional info. I use those on occasion as well. As far as I know it's
possible to loose data with any of the conversion functions. When I use
WIdeCharToMultiByte() at least I can look at the flag to see if that
happened (assuming the flag is a correct representation).

Tom

"Mihai N." <nmihai_year_2000(a)yahoo.com> wrote in message
news:Xns9890E63C0483DMihaiN(a)207.46.248.16...
> "Tom Serface" <tserface(a)msn.com> wrote in
> news:uRy8wWPGHHA.1804(a)TK2MSFTNGP02.phx.gbl:
>
>> Well a lot depends on how your project was compiled. If you compiled
>> non-Unicode then you won't have to convert really since the "T" will
> already
>> compile as "char" rather than "wchar_t". If you are using Unicode you
>> can
>> use WideCharToMultiByte() to convert.
>>
>> In either case the first is a const and the second, not so you will have
>> to
>> be careful how you use it. You could just assign either to a CString.
>> If
>> you assign to CStringW it will convert char * to wchar_t and if you
>> assign
>> to CStringA it will do the opposite. It's kind of handy, but you have to
> be
>> careful how you use it.
>
> Or "the easy way": T2A
> (with the warning that you might loose data).
>
>
> --
> Mihai Nita [Microsoft MVP, Windows - SDK]
> http://www.mihai-nita.net
> ------------------------------------------
> Replace _year_ with _ to get the real email


From: Joseph M. Newcomer on
It depends on what you mean by the question.

An LPCTSTR is a const TCHAR *, so do you mean you want to remove the const attribute, or
you really want a 'char *' data type (remember that char and char* represent an obsolete
technology that should be used only in very rare and exotic situations where you are
absolutely guarnteed because of external specs to be using 8-bit characters, and should
never be coded as a matter of course in any program).

If you really want a 'char *', that is, a pointer to an 8-bit character string, then you
have to explain why you need it and how you plan to handle the down-conversion from
Unicode characters that have no 8-bit equivalents.
joe

On Tue, 5 Dec 2006 20:20:31 -0600, rxgmoral <rxgmoral.2idl9p(a)mail.codecomments.com> wrote:

>
>How to LPCTSTR Convert to char *
>
>thank :)
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm