类型的实参与“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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM