CString sBuf;
...T("Response from QueryInfo is:\n%s"), (LPCSTR) sBuf);
I've always been able to cast to a const string. Why the error now?
error C2440: 'type cast' : cannot convert from 'CString' to 'LPCSTR'
I'm using VS2008. LPCSTR is typedefed to const CHAR*.
Ed Mitchell
--
Edward E.L. Mitchell
12214 Lakewood Ct
Fort Myers, FL 33908
Phone: (239)415-7039
Web: www.racesail.org
CString sBuf;
...T("Response from QueryInfo is:\n%s"), (LPCTSTR) sBuf);
HTH
"Edward Mitchell" <EELMi...@newsgroup.nospam> schrieb im Newsbeitrag
news:eyB$LNByJH...@TK2MSFTNGP03.phx.gbl...
AliR.
"Edward Mitchell" <EELMi...@newsgroup.nospam> wrote in message
news:eyB$LNByJH...@TK2MSFTNGP03.phx.gbl...
On Tue, 28 Apr 2009 11:09:12 -0400, "Edward Mitchell" <EELMi...@newsgroup.nospam>
wrote:
>Taking code from an old project, I now get an error that I can't convert a
>CString to an LPCSTR.
>
>CString sBuf;
>...T("Response from QueryInfo is:\n%s"), (LPCSTR) sBuf);
>
>I've always been able to cast to a const string. Why the error now?
>error C2440: 'type cast' : cannot convert from 'CString' to 'LPCSTR'
>
>I'm using VS2008. LPCSTR is typedefed to const CHAR*.
>
>Ed Mitchell
Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
Thanks.
Ed
"AliR (VC++ MVP)" <Al...@online.nospam> wrote in message
news:qaFJl.15517$%54....@nlpi070.nbdc.sbc.com...
Sorry if I sound rude, but did you understand why "The LPCTSTR fixed
the problem"? I say it because often, people accept the solution
without understanding it...
"Mikel" <mikel...@gmail.com> wrote in message
news:8b0101e0-c92b-4066...@c18g2000prh.googlegroups.com...
----- Original Message -----
From: "Mikel" <mikel...@gmail.com>
Newsgroups: microsoft.public.vc.mfc
Sent: Tuesday, April 28, 2009 12:59 PM
Subject: Re: Can't cast a CString to an LPCSTR
On 28 abr, 18:35, "Edward Mitchell" <EELMitch...@newsgroup.nospam>
wrote:
> It is a UNICODE project since I took the default. The LPCTSTR fixed the
> problem.
>
> Thanks.
>
> Ed
>
...
> Sorry if I sound rude, but did you understand why "The LPCTSTR fixed
> the problem"? I say it because often, people accept the solution
> without understanding it...
I've been pretty careful to always use a _T('...") for all the strings so I
know the "T" version varies between a WCHAR and a CHAR. Since my original
code worked in one of the earlier versions of VS, I presume the default must
have changed to the WCHAR when I come to use the 2008 version.
I was motivated to search for any LPCSTRs but there was only one!
Ed