From: Joy Maitland on
How can I convert CString to LPCTSTR ?

From: Alex Blekhman on
"Joy Maitland" wrote:
> How can I convert CString to LPCTSTR ?

You don't need to. CString already contains `operator LPCTSTR'.
Just pass CString object where LPCTSTR is expected.

HTH
Alex


From: Joy Maitland on
On Wed, 19 Nov 2008 11:41:22 +0200, "Alex Blekhman"
<tkfx.REMOVE(a)yahoo.com> wrote:

>"Joy Maitland" wrote:
>> How can I convert CString to LPCTSTR ?
>
>You don't need to. CString already contains `operator LPCTSTR'.
>Just pass CString object where LPCTSTR is expected.
>
>HTH
>Alex
>

you mean CString and LPCTSTR are same thing?

for a function that expect LPCSTR parameter, I can still pass in a
CString?

somefuncion (LPCTSTR string)

CString cc = "aaa";
somefunction ( cc );
From: Ulrich Eckhardt on
Joy Maitland wrote:
> On Wed, 19 Nov 2008 11:41:22 +0200, "Alex Blekhman"
> <tkfx.REMOVE(a)yahoo.com> wrote:
>>"Joy Maitland" wrote:
>>> How can I convert CString to LPCTSTR ?
>>
>>You don't need to. CString already contains `operator LPCTSTR'.
>>Just pass CString object where LPCTSTR is expected.
>
> you mean CString and LPCTSTR are same thing?

No, class CString has a user-defined conversion operator to LPCTSTR.

> for a function that expect LPCSTR parameter, I can still pass in a
> CString?
>
> somefuncion (LPCTSTR string)
>
> CString cc = "aaa";
> somefunction ( cc );

Yes, that works, exactly because of the above mentioned conversion.

Uli

--
C++ FAQ: http://parashift.com/c++-faq-lite

Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932
From: Alex Blekhman on
"Joy Maitland" wrote:
> you mean CString and LPCTSTR are same thing?

No, they are different types. But CString knows how to convert
itself to LPCTSTR if required.

> for a function that expect LPCSTR parameter,

You mean LPCTSTR, not LPCSTR, yes?

> I can still pass in a CString?
>
> somefuncion (LPCTSTR string)
>
> CString cc = "aaa";
> somefunction ( cc );

Yes, this will work. Also, you should use _T() macro if you want
to work with TCHAR's and CString:

CString cc = _T("aaa");

HTH
Alex