ATL 中调用ConvertBSTRToString报错无法解析的外部符号 "char * __stdcall _com_util::ConvertBSTRToString(wchar_t *)

ATL 中调用ConvertBSTRToString报错

#include   <comutil.h>  //_com_util::ConvertBSTRToString

#pragma   comment(lib,   "comsupp.lib")  //_com_util::ConvertBSTRToString

strTxt1 = _com_util::ConvertBSTRToString(bstrTxt1);  //调用例子 

报错内容:无法解析的外部符号 "char * __stdcall _com_util::ConvertBSTRToString(wchar_t *)

解决办法 :

#include   <comutil.h>  //_com_util::ConvertBSTRToString

#ifdef _UNICODE

#pragma   comment(lib,   "comsuppw.lib")  //_com_util::ConvertBSTRToString

#else

#pragma   comment(lib,   "comsupp.lib")  //_com_util::ConvertBSTRToString

#endif

原因:函数在Unicode编码中存在相应的Unicode版本的lib文件,而如果此时链接MultiChar多字节版本的lib文件,则会出现错误