AfxBeginThread函数decleration在哪里?

时间:2015-10-10 16:46:51

标签: c++ multithreading

此代码使用带有AfxBeginThread函数的线程,但我不知道我应该包含哪个头文件到我的项目中? 任何人都可以帮忙

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
    int nRetCode = 0;   

    cout << "Press ESCAPE to terminate program\r\n";
    AfxBeginThread(ServerThread,0);
    while(_getch()!=27);

    return nRetCode;
}

对于使用winsock的服务器使用线程的最佳方法是什么....

2 个答案:

答案 0 :(得分:0)

对于AfxBeginThread,您需要afxwin.h

答案 1 :(得分:0)

您还应添加:#define _AFXDLL

这是一个例子:

#define _AFXDLL //<<===notice this

#include <Afxwin.h>
#include <winsock2.h>
#include <winsock.h>
#include <windows.h>



#include <iostream>
//other C++ standard headers here as required
using namespace std;



// The one and only application object
CWinApp theApp;



UINT ThreadProc(LPVOID pParam)
{
  return 0;
}



int _tmain(int argc, _TCHAR* argv[])
{


    // initialize MFC
    if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
    {
        // TODO: change error code to suit your needs
        _tprintf(_T("Fatal Error: MFC initialization failed\n"));
        return 1;
    }

    int nRetCode = 0;  
    cout << "Press ESCAPE to terminate program\r\n";


    AfxBeginThread(ThreadProc,0);

    while(_getch()!=27);

    return nRetCode;

}