Re: passing a string to a dll

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance




"SteveR" <srussell@xxxxxxxxxxxxxxxxxxxxxx> wrote in message news:O0bV%23OZ%23HHA.1212@xxxxxxxxxxxxxxxxxxxxxxx

if(s != _T("12345") )

Call me paranoid, but...

Yes, I know there's a "!=" operator for this which should be used, but CString also has a cast to LPCTSTR and so it can read somewhat ambiguously that one might be just comparing the locations of the two strings. So I always use

if( s.Compare( _T("12345") ) )

in circumstances like this. (Also I tent to need CompareNoCase() as often as not, so I'm used to it.)

Dave
--
David Webber
Author of 'Mozart the Music Processor'
http://www.mozart.co.uk
For discussion/support see
http://www.mozart.co.uk/mzusers/mailinglist.htm

.



Relevant Pages

  • Re: Opinion on coding style.
    ... That's a legitimate cast. ... works well on a Formattype statement. ... force an LPCTSTR operator call. ... even if the string is a CString (you never know ...
    (microsoft.public.vc.language)
  • Pass CString to printf?
    ... Is it safe to pass a CString to printf without explicit (LPCTSTR) cast? ...
    (microsoft.public.vc.mfc)
  • Re: passing a string to a dll
    ... CString also has a cast to LPCTSTR and so it can read somewhat ambiguously ... that one might be just comparing the locations of the two strings. ...
    (microsoft.public.vc.mfc)
  • Re: printing CStrings with RETAILMSG macro
    ... You can't directly cast a CString to a LPCTSTR, but IIRC, there are two ...
    (microsoft.public.windowsce.embedded.vc)
  • Re: Pass CString to printf?
    ... Because of the way the CString class is designed, it is equal to the address of the string. ... By using the cast or calling the GetBuffermethod, you may be producing much more efficient code. ... Is it safe to pass a CString to printf without explicit (LPCTSTR) cast? ...
    (microsoft.public.vc.mfc)