我正在尝试在我的可可项目中实现USBPrivateDataSample 。问题是当我尝试为 struct MyPrivateData 分配内存时出现错误
“Assining 到“MyPrivateData *” 从不可抗类型 'void *'”
我的头文件中有结构定义:
#define kMyVendorID 0x0403
#define kMyProductID 0x6001
class RtMidiOut;
typedef struct MyPrivateData {
io_object_t notification;
IOUSBDeviceInterface **deviceInterface;
CFStringRef deviceName;
UInt32 locationID;
} MyPrivateData;
static IONotificationPortRef gNotifyPort;
static io_iterator_t gAddedIter;
static CFRunLoopRef gRunLoop;
@interface serialInput : NSObject{
...
我正在调用我的 .mm 文件:
void DeviceAdded(void *refCon, io_iterator_t iterator){
kern_return_t kr;
io_service_t usbDevice;
IOCFPlugInInterface **plugInInterface = NULL;
SInt32 score;
HRESULT res;
while ((usbDevice = IOIteratorNext(iterator))) {
io_name_t deviceName;
CFStringRef deviceNameAsCFString;
MyPrivateData *privateDataRef;
UInt32 locationID;
printf("Device added.\n");
// Add some app-specific information about this device.
// Create a buffer to hold the data.
privateDataRef = malloc(sizeof(MyPrivateData)); //The error!
bzero(privateDataRef, sizeof(MyPrivateData));
有什么有用的建议吗?