这是我的测试代码
#include "stdafx.h"
#include "windows.h"
#include "iostream"
using namespace std;
HANDLE hMutex;
static unsigned __stdcall threadFunc(void *params)
{
WaitForSingleObject(hMutex,INFINITE);
printf(":D:D:D\n");
ReleaseMutex(hMutex);
return NULL;
}
int _tmain(int argc, _TCHAR* argv[])
{
hMutex=CreateMutex(NULL,FALSE,NULL);
//first try
unsigned dwChildId;
_beginthreadex(NULL, 0, &threadFunc, NULL, 0, &dwChildId);
//second try
_beginthread(threadFunc, 0, NULL );
WaitForSingleObject(hMutex,INFINITE);
printf("HD\n");
ReleaseMutex(hMutex);
int i;
cin >> i;
return 0;
}
给我2个错误:
Error 1 error C3861: '_beginthreadex': identifier not found
Error 2 error C3861: '_beginthread': identifier not found
我使用 MFC 作为共享 DLL。我也不知道如何创建两个具有相同功能的线程。
在我包含“process.h”之后
Error 2 error C2664: '_beginthread' : cannot convert parameter 1 from 'unsigned int (__stdcall *)(void *)' to 'void (__cdecl *)(void *)'