不能在 MFC 中使用 _beginthreadex,错误为错误 C3861:'_beginthreadex':找不到标识符 beginthreadex 在没有 MFC 代码的情况下工作正常。
编辑:问题与文件包含序列有关,需要使用 _beginthreadex
// EventsHandshakeDlg.cpp : implementation file
//
#include <crtdefs.h>
#include <process.h>
#include"windowsx.h"
#include "stdafx.h"
unsigned int __stdcall/*AFX_THREADPROC*/ /*__cdecl*/ Server(void *iData)
{
}
// CEventsHandshakeDlg dialogCEventsHandshakeDlg::CEventsHandshakeDlg(CWnd* pParent /*=NULL*/)
: CDialog(CEventsHandshakeDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
BEGIN_MESSAGE_MAP(CEventsHandshakeDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_BTN_REVERSE, &CEventsHandshakeDlg::OnBnClickedBtnReverse)
END_MESSAGE_MAP()
// CEventsHandshakeDlg message handlers
BOOL CEventsHandshakeDlg::OnInitDialog()
{
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CEventsHandshakeDlg::OnBnClickedBtnReverse()
{unsigned int threadId = 0;
HANDLE Thread =(HANDLE)_beginthreadex(
NULL,
NULL,
&/*CEventsHandshakeDlg::*/Server/*(void *iData)*/,
NULL,
0,
&threadId
);
}