類型的實參與“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