描述:
STDMETHODIMP CTelnet::ExcTelnet(BSTR bstrCmd)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
// TODO: Add your implementation code here
char *p;
p = _com_util::ConvertBSTRToString(bstrCmd);
return S_OK;
}
开始我没加<COMUTIL.H>出现下列错误
F:\Web\BoCoWeb\Telnet.cpp(31) : error C2653: '_com_util' : is not a class or namespace name
F:\Web\BoCoWeb\Telnet.cpp(31) : error C2065: 'ConvertBSTRToString' : undeclared identifier
F:\Web\BoCoWeb\Telnet.cpp(31) : error C2440: '=' : cannot convert from 'int' to 'char *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.
加上<COMUTIL.H>出现下列错误
Creating library Debug/BoCoWeb.lib and object Debug/BoCoWeb.exp
Telnet.obj : error LNK2001: unresolved external symbol "char * __stdcall _com_util::ConvertBSTRToString(unsigned short *)" (?ConvertBSTRToString@_com_util@@YGPADPAG@Z)
Debug/BoCoWeb.dll : fatal error LNK1120: 1 unresolved externals
请大侠指点。分不是问题
解决方案1:
用CString有个问题, 如果是定义了_UNICODE的话, 那么代码就会出问题, 转出来的还是WCHAR的, 我认为还是显式的转比较好点
解决方案2:CString
解决方案3:我认为强制转换就可以了,CString
解决方案4: 你为什么不用转换宏呢
USES_CONVENSION;
W2A(bstrCmd);
好像是这样吧
为啥不用_bstr_t?
#include<comdef.h>
WCHAR str[]=L"sdafjk";//你的UNICODE字符串
_bstr_t str1=str;
char *str2=str1;