在使用利用CreateThread创建线程时

struct A
{
DWORD WINAPI MyThreadFunction(LPVOID) {}
void Run()
{
HANDLE hThread = CreateThread(
NULL, // default security attributes
0, // use default stack size
MyThreadFunction, // thread function name
0, // argument to thread function
0, // use default creation flags
NULL); // returns the thread identifier
}
};

visual studio 报了如下错误:

英文环境

E0167argument of type "DWORD (__stdcall A::*)()" is incompatible with parameter of type "LPTHREAD_START_ROUTINE"

中文环境

E0167 DWORD (__stdcall A::*)类型的实参与“LPTHREAD_START_ROUTINE”类型的形参不兼容

问题解决办法参考文档,将MyThreadFunction函数订单改为DWORD static WINAPI MyThreadFunction()

原因在ThreadProc callback function有描述

参考资料:

  1. ThreadProc callback function
  2. CreateThread function
05-11 22:27