tags:

views:

82

answers:

1

Recently, I have a utilities function of

// T2CA
#include "ATLCONV.H"

std::string Utils::CString2String(const CString& cString) 
{
#if _MSC_VER > 1200
    // Convert a TCHAR string to a LPCSTR
    // construct a std::string using the LPCSTR input
    CT2CA tmp(cString);
    std::string strStd (tmp);
#else
    // Deprecated in VC2008.
    // construct a std::string using the LPCSTR input

    std::string strStd (T2CA (cString));
#endif

    return strStd;
}

I do several simple test it seems work fine. However, when I google around, I see most usage of T2CA in VC6, before they call, they will invoke

USES_CONVERSION;

Is there any thing I had missed out? Shall I invoke my function by :

#else
    // Deprecated in VC2008.
    // construct a std::string using the LPCSTR input
    USES_CONVERSION;
    std::string strStd (T2CA (cString));
#endif
+1  A: 

In ATL 7.0 USES_CONVERSION is not required anymore. Before that you needed to specify the USES_CONVERSION macro or else you'd get compile errors.

Brian R. Bondy
But how come I didn't get any compilation error when I use T2CA? Take note T2CA is called with VC6 code block (#if _MSC_VER <= 1200)
Yan Cheng CHEOK
The above code can be compiled both under VC2008 and VC6.
Yan Cheng CHEOK
@Yan: I'm not sure but I remember before doing development and if I didn't put it I'd get compiling errors. And I know it's not required anymore. I think it's safe to say that you can safely use code without it if it compiles fine.
Brian R. Bondy
Oh, if I switch to unicode in VC6, I will get compilation error. Look like USES_CONVERSION is a must.
Yan Cheng CHEOK