1. 在stdafx.h中添加头文件afxsock.h
#include <afxsock.h>
2. 在你的App的InitInstance()函数的开头加入
if (!AfxSocketInit())
{
AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
return FALSE;
}
3. 在项目已有的类的实现文件(.cpp文件)中,添加头文件stdafx.h
#include "stdafx.h"
注意:
如果项目中的文件添加了Winsock之类的头文件,可以都去掉,否则会提示“redefinition”