From: David Wilkinson on
Eric Margheim wrote:

> GetString is a CSimpleStringT function.
>
> I know it's a bad idea but I'm trying to avoid rewriting the code that
> leverages the CStringEx class. I was hoping I could do some quick bandaid
> work and move on. We will be replacing this application soon anyhow.

OK, yes, I still use VC6 for MFC work, so I did not recognize GetString().

As AliR says, GetString() returns constant buffer. Maybe your buffer
should be constant also:

LPCTSTR lpszRemainder = GetString();

Or if you need a non-const buffer maybe you should look at GetBuffer().

--
David Wilkinson
Visual C++ MVP
From: Eric Margheim on

"AliR (VC++ MVP)" <AliR(a)online.nospam> wrote in message
news:wzOSh.2070$w41.1597(a)newssvr19.news.prodigy.net...
> GetString returns a const pointer. Try PCTSTR or LPCSTR
>
> AliR.


Thanks

Actually the conversion problem wasn't with the GetString function but with
the other string manipulation functions that were returning const char*. I
just cast those returns to LPTSTR. We'll see if that works.


From: Joseph M. Newcomer on
It is safe to assume that subclassing CString is erroneous, and therefore, you will have
to rewrite the code.

See below...
On Tue, 10 Apr 2007 10:53:30 -0500, "Eric Margheim" <NOSPAM***eric(a)prism-grp.com***NOSPAM>
wrote:

>I have a dumb question... :-)
>
>I am converting an app to VS2005 and have inherited some legacy code that is
>a class inherited from CString. It references m_pchData quite a bit. I
>am trying to use GetString() instead but am running into variable conversion
>issues.
>
>LPTSTR lpsz, lpszRemainder = GetString(), lpszret;
>
>This fails with the following:
>
>1>.\stringex.cpp(294) : error C2440: 'initializing' : cannot convert from
>'const char *' to 'LPTSTR'
****
It has to be an LPCTSTR. Also, the style is truly abysmal. I consider it extremely poor
practice to use a comma in a delcaration list. This should be done as
LPTSTR lpsz;
LPCTSTR lpszRemainder = GetString();
LPTSTR lpszret;

one line per variable, period. Otherwise, it is hard to read. And you get weird cases
where you lump declarations together and it quite possibly would be the case that
declaring the buffer as an LPCTSTR is sufficient, but the poor syntactic construction
makes it less obvious how to make the fix.
****
>
>How can I convert the GetString() to the LPTSTR? I really don't want to
>rewrite any more than I have to to get this to compile.
****
Change the declaration. Since you haven't shown how it is being used, it is hard to say
if the simple change to LPCTSTR is sufficient, but that's about the best you're going to
get.

Code that subclasses CString is a candidate for rewrite. You may not have an option.
joe
****
>
>Thanks
>
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Joseph M. Newcomer on
Casting to LPTSTR might not be safe, because there are assumptions about the mutability of
the contents. Using an LPCTSTR would at least make sure the necessary preconditions were
met.
joe

On Tue, 10 Apr 2007 11:47:02 -0500, "Eric Margheim" <NOSPAM***eric(a)prism-grp.com***NOSPAM>
wrote:

>
>"AliR (VC++ MVP)" <AliR(a)online.nospam> wrote in message
>news:wzOSh.2070$w41.1597(a)newssvr19.news.prodigy.net...
>> GetString returns a const pointer. Try PCTSTR or LPCSTR
>>
>> AliR.
>
>
>Thanks
>
>Actually the conversion problem wasn't with the GetString function but with
>the other string manipulation functions that were returning const char*. I
>just cast those returns to LPTSTR. We'll see if that works.
>
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Eric Margheim on

"Joseph M. Newcomer" <newcomer(a)flounder.com> wrote in message
news:1bin13pv3ak0v8djon58pdtckru57tnuv4(a)4ax.com...
> Casting to LPTSTR might not be safe, because there are assumptions about
> the mutability of
> the contents. Using an LPCTSTR would at least make sure the necessary
> preconditions were
> met.
> joe
>

OK. Thanks Joe.