类型的实参与“LPTHREAD

mac2022-06-30  77

在使用利用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.

参考资料:

ThreadProc callback functionCreateThread function

转载于:https://www.cnblogs.com/lkpp/p/incompatible_parameter_LPTHREAD_START_ROUTINE.html

最新回复(0)