在线程函数中的函数指针问题
cynew 2005-08-11 01:11:10 本来我是直接把一个函数名设给CreateThread函数的,代码如下:
hThread = CreateThread(
NULL, // default security attributes
0, // use default stack size
Hunter, // thread function
(LPVOID)pslfinx, // argument to thread function
CREATE_SUSPENDED, // use default creation flags
&dwThreadId);
Hunter为线程函数,声明为:DWORD WINAPI Hunter(LPVOID);
但是我想把CreateThread再往上包一层,所以想把一个函数指针传给CreateThread,于是我这样写:
typedef DWORD WINAPI DWWIN;
typedef DWWIN (*PFUNC)(LPVOID);
int StateMonitor::MonitorCreateThread(int Index,LPVOID p,PFUNC pfun)
{
......
DWORD dwThreadId;
HANDLE hThread;
hThread = CreateThread(
NULL, // default security attributes
0, // use default stack size
*pfun, // thread function
(LPVOID)pslfinx, // argument to thread function
CREATE_SUSPENDED, // use default creation flags
&dwThreadId);
............
但是编译的时候总是说CreateThread的第三个参数错误:
CreateThread' : cannot convert parameter 3 from 'unsigned long (__cdecl *)(void *)' to 'unsigned long (__stdcall *)(void *)'
这就奇怪了,我没有用函数指针,直接把函数传给她的时候就正确,用函数指针传就错误~~~郁闷了~