大佬教程收集整理的这篇文章主要介绍了c – 如何创建程序列出Mac中的所有USB设备?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
或者,您可以使用IOServiceGetMatchingServices
获取所有当前匹配服务的迭代器,使用由IOserviceMatching(kIoUSBDeviceClassName)创建的字典。
以下是一个简短的示例(我从未运行过):
#include <IOKit/IOKitLib.h> #include <IOKit/usb/IoUSBLib.h> int main(int argc,const char *argv[]) { CFMutableDictionaryRef matchingDict; io_iterator_t iter; kern_return_t kr; io_service_t device; /* set up a matching Dictionary for the class */ matchingDict = IOserviceMatching(kIoUSBDeviceClassName); if (matchingDict == NULL) { return -1; // fail } /* Now we have a Dictionary,get an iterator.*/ kr = IOserviceGetMatchingservices(kIOMasterPortDefault,matchingDict,&iter); if (kr != KERN_succesS) { return -1; } /* iterate */ while ((device = IOIteratorNext(iter))) { /* do something with device,eg. check properties */ /* ... */ /* And free the reference taken before conTinuing to the next item */ IOObjectRelease(devicE); } /* Done,release the iterator */ IOObjectRelease(iter); return 0; }
以上是大佬教程为你收集整理的c – 如何创建程序列出Mac中的所有USB设备?全部内容,希望文章能够帮你解决c – 如何创建程序列出Mac中的所有USB设备?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。