用 comsupp.lib/comsuppd.lib 还是 comsuppw.lib/comsuppwd.lib

曾经用过 _bstr_t 类,MSDN 提示包含的库为 comsuppw.lib 或 comsuppwd.lib。

 

最近看到了 comsupp.lib 和 comsuppd.lib,到底该用哪个呢?

 

从 MSDN 得知:

(1) 当指定了 /Zc:wchar_t  时,应该使用comsuppw.lib/comsuppwd.lib;

(2) 当指定了 /Zc:wchar_t- 时,应该使用comsupp.lib/comsuppd.lib。

P.S.:/Zc:wchar_t 或 /Zc:wchar_t- 可通过“项目属性 -> 配置属性 -> C/C++ -> 语言 -> 将 WChar_t  视为内置类型”设定。

 

原文:

Explicit references to comsupp.lib, either from the comment pragma or via the command line, should be changed to now use either comsuppw.lib or comsuppwd.lib, as /Zc:wchar_t is now on by default. comsupp.lib should still be used when compiling with /Zc:wchar_t-.

 

如果希望代码能根据项目属性设置而自适应,可以通过 _NATIVE_WCHAR_T_DEFINED 来判定。代码如下:

#include #include #ifndef _NATIVE_WCHAR_T_DEFINED // DO NOT use _WCHAR_T_DEFINED. # pragma message(" - _NATIVE_WCHAR_T_DEFINED is NOT defined. ") // Test if macor _WCHAR_T_DEFINED is defined or not. # ifdef _WCHAR_T_DEFINED # pragma message(" - _WCHAR_T_DEFINED is defined. ") # else # pragma message(" - _WCHAR_T_DEFINED is NOT defined. ") # endif // _WCHAR_T_DEFINED // Test Debug or Release is compiled, and referenced corresponding lib. # ifdef _DEBUG # pragma message(" - comsuppd.lib is referenced. ") # pragma comment(lib, "comsuppd.lib") # else # pragma message(" - comsupp.lib is referenced. ") # pragma comment(lib, "comsupp.lib") # endif // _DEBUG #else # pragma message(" - _NATIVE_WCHAR_T_DEFINED is defined. ") // Test if macor _WCHAR_T_DEFINED is defined or not. # ifdef _WCHAR_T_DEFINED # pragma message(" - _WCHAR_T_DEFINED is defined. ") # else # pragma message(" - _WCHAR_T_DEFINED is NOT defined. ") # endif // _WCHAR_T_DEFINED // Test Debug or Release is compiled, and referenced corresponding lib. # ifdef _DEBUG # pragma message(" - comsuppwd.lib is referenced. ") # pragma comment(lib, "comsuppwd.lib") # else # pragma message(" - comsuppw.lib is referenced. ") # pragma comment(lib, "comsuppw.lib") # endif // _DEBUG #endif // _NATIVE_WCHAR_T_DEFINED int main() { _bstr_t bstrStr = _bstr_t(L"Hello, World! "); std::cout << bstrStr << std::endl; return 0; }

 

关于两个宏的解释如下:

_WCHAR_T_DEFINED: Defined when /Zc:wchar_t is used or if wchar_t is defined in a system header file included in your project. 

_NATIVE_WCHAR_T_DEFINED: Defined when /Zc:wchar_t is used.

你可能感兴趣的:(C/C++)