我的接口函数如下:
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类型的 请教大侠我该做如何转换才可以啊?????

解决方案 »

  1.   

    STDMETHODIMP UdpChat::SendChatMsg(BSTR IpAddress, LONG port, BSTR Msg)
    {
    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 个链接错误是什么意思啊 该如何解决呢?
      

  2.   

    #pragma comment(lib,"comsupp.lib")