类型的实参与“LPTHREAD_START_ROUTINE”类型的形参不兼容

在使用利用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 报了如下错误:
英文环境
E0167 argument 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有描述

Each thread receives a unique copy of the local variables of this function. Any static or global variables are shared by all threads in the process.

参考资料:

  1. ThreadProc callback function
  2. CreateThread function
posted @ 2019-08-03 18:50  ,,,沙子,,,  阅读(3073)  评论(0编辑  收藏  举报