獲取設備的廠商字符串
阿新 • • 發佈:2018-08-26
add okit 忽略 創建 driver con amp match ctr
//
// main.c
// DriverIterator
//
#include <CoreFoundation/CoreFoundation.h>
#include <IOKit/IOKitLib.h>
void DeviceAdded (void* refCon, io_iterator_t iterator)
{
io_service_t service = 0;
// 叠代所有匹配對象
while ((service = IOIteratorNext(iterator)) != 0)
{
CFStringRef className;
//列出所有的IOUSBDevice對象 ,忽略IOUSBDevice的子類對象
className = IOObjectCopyClass(service);
if (CFEqual(className, CFSTR("IOUSBDevice")) == true)
{
CFTypeRef vendorName;
vendorName = IORegistryEntryCreateCFProperty(service, CFSTR("USB Vendor Name"), kCFAllocatorDefault, 0);
CFShow(vendorName);
}
CFRelease(className);
IOObjectRelease(service);
}
}
int main (int argc, const char * argv[])
{
CFDictionaryRef matchingDict = NULL;
io_iterator_t iter = 0;
IONotificationPortRef notificationPort = NULL;
CFRunLoopSourceRef runLoopSource;
kern_return_t kr;
//創建一個匹配字典,用於查找任意的 USB 設備
matchingDict = IOServiceMatching("IOUSBDevice");
notificationPort = IONotificationPortCreate(kIOMasterPortDefault);
runLoopSource = IONotificationPortGetRunLoopSource(notificationPort);
CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopDefaultMode);
kr = IOServiceAddMatchingNotification(notificationPort, kIOFirstMatchNotification, matchingDict, DeviceAdded, NULL, &iter);
DeviceAdded(NULL, iter);
CFRunLoopRun();
IONotificationPortDestroy(notificationPort);
IOObjectRelease(iter);
return 0;
}
Apple Inc.
Apple Inc.
(null)
Kingston
獲取設備的廠商字符串