我正在尝试将类内部的回调函数绑定到Functionpointer,但是我似乎无法使其正常工作。 我正在使用第三方API,因此我无法更改其期望功能的方式。 一切正常,直到我尝试将代码抽象为类结构为止。
// API header
typedef DWORD (__stdcall *PHIDDataEvent)(UCHAR *pData, DWORD deviceID, DWORD error);
extern "C" DWORD __stdcall SetDataCallback(long hnd, PHIDDataEvent pDataEvent);
// myclass.h
class Devices
{
public:
Devices(DWORD ID);
~Devices();
private:
DWORD __stdcall HandleDataEvent(UCHAR *pData, DWORD deviceID, DWORD error);
void CreateCallback();
DWORD deviceID;
};
//myclass.cpp
#include "myclass.h"
#include "APIHeader.h"
Devices::Devices()
{
CreateCallback();
}
DWORD __stdcall Devices::HandleDataEvent(UCHAR *pData, DWORD deviceID, DWORD error)
{
//callback code is in here
}
void Devices::CreateCallback()
{
int result;
result = SetDataCallback(deviceID,this->HandleDataEvent);
/*intellisense is not complaining, compiler trhows error C3867: 'Devices::HandleDataEvent':
non-standard syntax; use '&' to create a pointer to member */
}
我如何使功能指针起作用? 亲切的问候 pccrash