qt中链接动态链接库,调用其中的函数,该函数的参数需要传入回调函数,自己创建的回调函数无法作为参数传递进去
typedef void (*SearchUSBPrinters1)(GetUSBPrinter_CallbackProc , unsigned char * );
SearchUSBPrinters1 fun = (SearchUSBPrinters1)myDll.resolve("SearchUSBPrinters");
fun(Widget::getUSBPrinter_CallbackProc,(unsigned char *)"HK");
void Widget::getUSBPrinter_CallbackProc(getprinterinfo_usbPrinterStateParms_Type *usbPrinterState)
{
usableUSBPrinterList_Type *curUSBPL;//定义了一个结构体指针
int currentFoundUSBPrinterNumber;
if (usbPrinterState == NULL)
return;
printf("\nEnter the USB printer discovery call-back processing :register into the USB printer list.\n");//进入USB打印机发现回调处理:注册到USB打印机列表中
if ((curUSBPL = (usableUSBPrinterList_Type *)malloc(sizeof(usableUSBPrinterList_Type))) == NULL)//给curUSBPL数组分配内存,判断是否为空
memset(curUSBPL , 0 , sizeof(usableUSBPrinterList_Type));//数组内的值都设定为0
curUSBPL->usbPrinterState = usbPrinterState;//将得到的值传给curUSBPL结构体指针中的usbPrinterState成员变量
if (currentUSBPrinterList == NULL)//如果当前USB打印机当前列表指针为空
currentUSBPrinterList = curUSBPL;//将数组的首地址赋值给-USB打印机当前列表指针
else
curUSBPL->next = currentUSBPrinterList;//调用结构体的next的成员变量,把-USB打印机当前列表指针-赋值给next
currentUSBPrinterList = curUSBPL;//将数组首地址传给列表指针
currentFoundUSBPrinterNumber ++;//当前找到的打印机编号加一
}
我自己定义的回调函数与fun()回调函数类型不匹配
程序编译后出现以下错误
D:\Mine\ku\7_55\7_55\widget.cpp:54: error: cannot convert 'Widget::getUSBPrinter_CallbackProc' from type 'void (Widget::)(Widget::getprinterinfo_usbPrinterStateParms_Type*)' {aka 'void (Widget::)(Widget::getprinterinfo_usbPrinterStateParms_S*)'} to type 'GetUSBPrinter_CallbackProc' {aka 'void ()(getprinterinfo_usbPrinterStateParms_S)'}
..\7_55\widget.cpp: In constructor 'Widget::Widget(QWidget*)':
..\7_55\widget.cpp:54:14: error: cannot convert 'Widget::getUSBPrinter_CallbackProc' from type 'void (Widget::)(Widget::getprinterinfo_usbPrinterStateParms_Type*)' {aka 'void (Widget::)(Widget::getprinterinfo_usbPrinterStateParms_S*)'} to type 'GetUSBPrinter_CallbackProc' {aka 'void ()(getprinterinfo_usbPrinterStateParms_S)'}
54 | fun(Widget::getUSBPrinter_CallbackProc,(unsigned char *)"HK");
| ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
怎么解决这个问题