【求助】调用CString类型出错
VC++6.0(实在是有点老得没渣了,没办法,只会用这个,请见谅)代码:
#include <afx.h>
#include "fun_iocpsvr.h"
#include <stdio.h>
char *buffer = "Received..";
//高效稳定的完成端口动态库
//
//Powered by
//
//
//
//2009-6-19
Tfun_iocpsvr *fun_iocpsvr = NULL;
//-----------------------------------------------------------------
__stdcall Tfun_iocpsvr::Tfun_iocpsvr(char *ip,int port)
{
m_iocp_obj = NULL;
//------------------------------
dll_iocplib = new Tdll_iocplib();
#ifdef _DEBUG
dll_iocplib->load_dll_lib(L"iocplibd.dll");
#else
dll_iocplib->load_dll_lib(L"iocplib.dll");
#endif
//-----------------------------------------------
dll_iocplib->load_lib_function();
dll_iocplib->fun_create_iocplib(&m_iocp_obj);
m_iocp_obj->start_iocp(ip,port);
m_iocp_obj->set_fun_proc((IOCP_ACCEPT)iocp_accept,
(IOCP_RECV_MESSAGE)iocp_recv,
(IOCP_CLOSE)iocp_close,
(void*)this);
}
//-----------------------------------------------------------------
__stdcall Tfun_iocpsvr::~Tfun_iocpsvr()
{
if(m_iocp_obj)
{
m_iocp_obj->stop_iocp();
dll_iocplib->fun_delete_iocplib(&m_iocp_obj);
}
m_iocp_obj = NULL;
delete dll_iocplib;
dll_iocplib = NULL;
}
//-----------------------------------------------------------------
void __stdcall Tfun_iocpsvr::iocp_accept(tag_iocp_node *user_node,void *param)
{
Tfun_iocpsvr *m_this = (Tfun_iocpsvr*)param;
m_this->fun_accept(user_node);
}
//-----------------------------------------------------------------
void __stdcall Tfun_iocpsvr::iocp_recv(tag_iocp_node *user_node,void *param)
{
Tfun_iocpsvr *m_this = (Tfun_iocpsvr*)param;
m_this->fun_recv(user_node);
}
//-----------------------------------------------------------------
void __stdcall Tfun_iocpsvr::iocp_close(tag_iocp_node *user_node,int close_type,void *param)
{
Tfun_iocpsvr *m_this = (Tfun_iocpsvr*)param;
m_this->fun_close(user_node,close_type);
}
//-----------------------------------------------------------------
//-----------------------------------------------------------------
//-----------------------------------------------------------------
//-----------------------------------------------------------------
void __stdcall Tfun_iocpsvr::fun_accept(tag_iocp_node *user_node)
{
//连接到来时,同时也有消息需要提取,这是完成端口的与众不同之处之一
char *sock_buf = user_node->szBuffer;
int sock_len = user_node->szBuffer_len;
//处理实际的socket数据
printf("\n %s len: %d \n",sock_buf,sock_len);
m_iocp_obj->send_message(user_node,buffer,strlen(buffer));
static int i_connect_count = 0;
i_connect_count ++;
//---
printf("\n有连接来了: %lu \n",i_connect_count);
}
//-----------------------------------------------------------------
void __stdcall Tfun_iocpsvr::fun_recv(tag_iocp_node *user_node)
{
char *sock_buf = user_node->szBuffer;
int sock_len = user_node->szBuffer_len;
if(sock_len > 0)
{
//处理实际的socket数据
printf("\n %s \n",sock_buf);
m_iocp_obj->send_message(user_node,buffer,strlen(buffer));
}
CString str="123123123";
printf(str);
}
//-----------------------------------------------------------------
void __stdcall Tfun_iocpsvr::fun_close(tag_iocp_node *user_node,int close_type)
{
//用户节点即将关闭之前发来的调用
static int i_deconnect_count = 0;
i_deconnect_count ++;
printf("\n有连接关闭: %lu : %d \n",i_deconnect_count, close_type);
}
testiocp(修改).rar
(1.96 MB)
调试信息如下:
--------------------Configuration: testiocp - Win32 Debug--------------------
Compiling...
fun_iocpsvr.cpp
Linking...
nafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) already defined in LIBCD.lib(new.obj)
nafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete(void *)" (??3@YAXPAX@Z) already defined in LIBCD.lib(dbgdel.obj)
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __endthreadex
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __beginthreadex
Debug/testiocp.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.
Creating browse info file...
testiocp.exe - 1 error(s), 0 warning(s)
在一个网上下载的名为《高效稳定的完成端口动态库》的IOCP例子中,需要用到CString类型的变量,所以#include <afx.h>;
然后就出错了,不是很明白,请教一下如何解决。
附件中的例子已经被我修改了,即会出错。
[ 本帖最后由 new_daimon 于 2015-4-28 14:10 编辑 ]