我的接口函数如下:
STDMETHODIMP UdpChat::SendChatMsg(BSTR IpAddress, LONG port, BSTR Msg)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState()) // TODO: Add your implementation code here
//将要发送的内容转换成ANSI字符串
_bstr_t bstrMsg = Msg;
char* lpszMsg = bstrMsg;
//发送
m_sSocket.SendTo(lpszMsg,(int)strlen(lpszMsg),port,IpAddress);
return S_OK;
}
其中SendTo的第4 个参数的类型上报错误:
error C2664: 'int __thiscall CAsyncSocket::SendTo(const void *,int,unsigned int,const char *,int)' : cannot convert parameter 4 from 'unsigned short *' to 'const char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style castSendTo的第4 个参数是LPCTSTR类型的 请教大侠我该做如何转换才可以啊?????
STDMETHODIMP UdpChat::SendChatMsg(BSTR IpAddress, LONG port, BSTR Msg)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState()) // TODO: Add your implementation code here
//将要发送的内容转换成ANSI字符串
_bstr_t bstrMsg = Msg;
char* lpszMsg = bstrMsg;
//发送
m_sSocket.SendTo(lpszMsg,(int)strlen(lpszMsg),port,IpAddress);
return S_OK;
}
其中SendTo的第4 个参数的类型上报错误:
error C2664: 'int __thiscall CAsyncSocket::SendTo(const void *,int,unsigned int,const char *,int)' : cannot convert parameter 4 from 'unsigned short *' to 'const char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style castSendTo的第4 个参数是LPCTSTR类型的 请教大侠我该做如何转换才可以啊?????
解决方案 »
- 如何清除socket的输入输出缓冲区
- lib文件夹下的文件,是不是\crt\src\下的源文件编译后的结果呢?
- 编辑框
- 请问怎样更改控件的右键默认菜单?
- 如何实现xml文件的关键字搜索?????????????
- 类中静态线程函数调用本类的其他静态成员函数和调用其他类的成员函数的奇怪问题,请指点解释。
- 在98下,如何禁用“重新启动计算机并切换到MS-DOS方式“??
- 超简单问题,按钮怎么为无效?要用程序设定
- 下面代码的release版本会导致死机,谁能帮我看一下?
- _Recordset的find()怎么用?
- 使用内存dc时,必须要把一个HBITMAP选入其中么?否则dc所对应的像素数据保存在哪里?
- ACE/TAO问题
{
AFX_MANAGE_STATE(AfxGetStaticModuleState()) // TODO: Add your implementation code here
CString Host(IpAddress);
//将要发送的内容转换成ANSI字符串
_bstr_t bstrMsg = Msg;
char* lpszMsg = bstrMsg;
//发送
m_sSocket.SendTo(lpszMsg,(int)strlen(lpszMsg),port,(LPCTSTR)Host);
return S_OK;
}
这样修改之后那个编译错误没了,但是出现3个链接错误。
UdpChat.obj : error LNK2001: unresolved external symbol "void __stdcall _com_issue_error(long)" (?_com_issue_error@@YGXJ@Z)
UdpChat.obj : error LNK2001: unresolved external symbol "char * __stdcall _com_util::ConvertBSTRToString(unsigned short *)" (?ConvertBSTRToString@_com_util@@YGPADPAG@Z)
Debug/ChatCom.dll : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.
谁能帮我解释一下这3 个链接错误是什么意思啊 该如何解决呢?