不使用USES_CONVERSION会有什么副作用?

4

最近我制作了一个实用程序函数,如下:

// 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;
}

我做了几个简单的测试,看起来效果很好。但是当我在网上搜索时,我发现VC6中T2CA的大多数用法都有一个先前的调用。

USES_CONVERSION;

我有什么遗漏吗?我应该通过什么方式调用我的函数:

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

4
在ATL 7.0中,不再需要使用USES_CONVERSION。在此之前,您需要指定USES_CONVERSION宏,否则将出现编译错误。

但是当我使用T2CA时,为什么没有任何编译错误呢?请注意,T2CA是在VC6代码块(#if _MSC_VER <= 1200)中调用的。 - Cheok Yan Cheng
@Yan:我不确定,但我记得以前开发时如果没有加上它就会出现编译错误。而且现在已经不再需要了。我认为可以肯定地说,如果代码编译正常,那么你可以安全地使用它而不必加上它。 - Brian R. Bondy
哦,如果我在VC6中切换到Unicode,就会出现编译错误。看起来必须使用USES_CONVERSION。 - Cheok Yan Cheng

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接