其中是AfxBeginThread函数声明

Where is AfxBeginThread function decleration?

本文关键字:函数 声明 AfxBeginThread      更新时间:2023-10-16

这个代码使用线程与AfxBeginThread函数,但我不知道我应该包括什么头文件到我的项目?
有人能帮忙吗?

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
    int nRetCode = 0;   
    cout << "Press ESCAPE to terminate programrn";
    AfxBeginThread(ServerThread,0);
    while(_getch()!=27);
    return nRetCode;
}

和使用winsock的服务器使用线程的最佳方式是什么....

你还应该加上:#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 failedn"));
        return 1;
    }
    int nRetCode = 0;  
    cout << "Press ESCAPE to terminate programrn";

    AfxBeginThread(ThreadProc,0);
    while(_getch()!=27);
    return nRetCode;
}

对于AfxBeginThread,您需要afxwin.h