我使用CreateThread函数在C++中编写类似C#BackgroundWorker的类.我的代码:
BackgroundWorker.h:
class BackgroundWorker
{
private :
HANDLE _threadHandle;
unsigned int _threadCallcounter;
DWORD _threadID;
public:
BackgroundWorker();
~BackgroundWorker();
virtual DWORD WINAPI Function(LPVOID vpPram);
}
Run Code Online (Sandbox Code Playgroud)
BackgroundWorker.cpp:
#include "BackgroundWorker.h"
void BackgroundWorker::DoWork()
{
this->_threadHandle = CreateThread(NULL,
0,this->Function,&this->_threadCallcounter,
0, &this->_threadID); // !!!***This part throws an error***!!!
}
Run Code Online (Sandbox Code Playgroud)
然后我创建了另一个派生自BackgroundWorker的类:
ListenThread.cpp:
class ListenThread :public BackgroundWorker
{
DWORD WINAPI Function(LPVOID vpPram)
{
//DO somthing...
return 0;
}
};
Run Code Online (Sandbox Code Playgroud)
但该行给了我以下错误:
非标准语法; 使用'&'创建指向成员的指针