我在Objective-C类中有一个方法。它具有用C编写的2个回调函数。类指针,即self
作为void *
传递给这些函数。在C函数中,我创建了一个类型指针并分配了参数void *
。 第一个回调函数成功执行。但在第二个回调函数中void *
指针变为nil
。请注意,我在第一次回调中没有调整指针,但仍然在第二次回调中获得nil
。处理回调
任何想法可能会出错?
例如:
kr = IOServiceAddMatchingNotification(gNotifyPort, kIOFirstMatchNotification,
matchingDict, RawDeviceAdded, NULL,
&gRawAddedIter);
RawDeviceAdded(NULL, gRawAddedIter, self);
这工作得很好。但以下功能收到self
为nil
。
kr = IOServiceAddMatchingNotification(gNotifyPort, kIOFirstMatchNotification,
matchingDict, BulkTestDeviceAdded, NULL,
&gBulkTestAddedIter);
BulkTestDeviceAdded(NULL, gBulkTestAddedIter, self);
这将是更容易帮助,如果你可以编辑添加代码,显示你正在试图做什么。 – 2008-11-25 10:17:18