在C+中注册回调+;从操纵杆设备库 我找到了一个库来处理C++中的操纵杆USB设备。 因此,我试图将它的回调附加到我的应用程序中。所以它有以下定义 struct Gamepad_device { unsigned int deviceID; const char * description; int vendorID; int productID; unsigned int numAxes; unsigned int numButtons; float * axisStates; bool * buttonStates; void * privateData; }; [...] /* Registers a function to be called whenever a device is attached. The specified function will be called only during calls to Gamepad_init() and Gamepad_detectDevices(), in the thread from which those functions were called. Calling this function with a NULL argument will stop any previously registered callback from being called subsequently. */ void Gamepad_deviceAttachFunc (void (* callback) (struct Gamepad_device * device, void * context), void * context);

在C+中注册回调+;从操纵杆设备库 我找到了一个库来处理C++中的操纵杆USB设备。 因此,我试图将它的回调附加到我的应用程序中。所以它有以下定义 struct Gamepad_device { unsigned int deviceID; const char * description; int vendorID; int productID; unsigned int numAxes; unsigned int numButtons; float * axisStates; bool * buttonStates; void * privateData; }; [...] /* Registers a function to be called whenever a device is attached. The specified function will be called only during calls to Gamepad_init() and Gamepad_detectDevices(), in the thread from which those functions were called. Calling this function with a NULL argument will stop any previously registered callback from being called subsequently. */ void Gamepad_deviceAttachFunc (void (* callback) (struct Gamepad_device * device, void * context), void * context);,c++,callback,usb,game-engine,joystick,C++,Callback,Usb,Game Engine,Joystick,因此,我试图将这个函数Gamepad_deviceAttachFunc附加到我的应用程序中的私有函数 我尝试使用注册我的私人功能joystickIsAttached(Gamepad\u设备) Gamepad_deviceAttachFunc(joystickIsAttached(*Gamepad_device)); 及 但两者都让我想到了 错误:在“')标记之前应该有主表达式 Gamepad_设备连接功能(joystickIsAttached(*Gamepad_设备)) 或 错误:在“')标记

因此,我试图将这个函数Gamepad_deviceAttachFunc附加到我的应用程序中的私有函数

我尝试使用注册我的私人功能
joystickIsAttached(Gamepad\u设备)

Gamepad_deviceAttachFunc(joystickIsAttached(*Gamepad_device));

但两者都让我想到了

错误:在“')标记之前应该有主表达式 Gamepad_设备连接功能(joystickIsAttached(*Gamepad_设备))

错误:在“')标记之前应该有主表达式 Gamepad_设备连接(连接了joystickIsAttached(Gamepad_设备))

更新

我还尝试将被调用的函数定义为

void joystickDeviceAttachedCallback
   (struct Gamepad_device * device, void * context);
并使用

Gamepad_deviceAttachFunc(joystickDeviceAttachedCallback, (void *) 0x1);
但这导致了

错误:无法转换“MainWindow::joystickDeviceAttachedCallback” 从类型“void(主窗口:)(游戏板设备*,void*)”到类型“void” ()(Gamepad_设备,void*)' Gamepad_deviceAttachFunc(joystickDeviceAttachedCallback,(void*)0x1)

那么,我做错了什么(我该如何修复它?)


谢谢。

您是否应该在定义的函数中传递结构而不使用*引用,基本上是通过值传递的?我也试过了。但是没有成功。可能是因为这个函数是MainWindow类的一部分,或者是因为这个错误——如果是,也许你可以把它从类中拉出来?
Gamepad_deviceAttachFunc(joystickDeviceAttachedCallback, (void *) 0x1);