Prev: "Detaching" a non-modal dialog from it's parent main frame
Next: Not enough storage is available to process this command
From: Eric Margheim on 10 Apr 2007 15:17 "David Wilkinson" <no-reply(a)effisols.com> wrote in message news:Oxdfm64eHHA.4136(a)TK2MSFTNGP02.phx.gbl... > 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(). > Thanks. This is what I ended up doing. I converted all my LPTSTR variables to LPCTSTRs per Joe's suggestion to avoid casting to LPTSTR.
From: Eric Margheim on 10 Apr 2007 15:22 "Joseph M. Newcomer" <newcomer(a)flounder.com> wrote in message news:m0hn13tcoiiqbetk85isfg1ct76qldch5h(a)4ax.com... > 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. > **** I agree. I didn't write the code. The issue is if this takes me more than an hour or so to convert to VS2005 then I'm going to just tell the original developer to reinstall VS6 and work with it there. It does work so I don't want to rewrite since the app is going to be completely replaced by something else in the near future.
From: Joseph M. Newcomer on 10 Apr 2007 20:03
Given the presence of a subclassed CString, I'd be inclined to keep it in VS6. There's no guarantee that the conversion is going to work anyway. joe On Tue, 10 Apr 2007 14:22:05 -0500, "Eric Margheim" <NOSPAM***eric(a)prism-grp.com***NOSPAM> wrote: > >"Joseph M. Newcomer" <newcomer(a)flounder.com> wrote in message >news:m0hn13tcoiiqbetk85isfg1ct76qldch5h(a)4ax.com... >> 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. >> **** > >I agree. I didn't write the code. The issue is if this takes me more >than an hour or so to convert to VS2005 then I'm going to just tell the >original developer to reinstall VS6 and work with it there. It does work so >I don't want to rewrite since the app is going to be completely replaced by >something else in the near future. > Joseph M. Newcomer [MVP] email: newcomer(a)flounder.com Web: http://www.flounder.com MVP Tips: http://www.flounder.com/mvp_tips.htm |