本文介绍了在目标C中获取图形卡信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在我的应用程序中获取图形卡信息.我需要的信息与图形/显示:部分下的 * system_profiler SPDisplays * 命令显示的信息相同.我已经考虑过使用 sysctl() ,但是我无法在sysctl.h中找到合适的图形卡硬件选择器.
I need to get Graphics card information in my application. The information I need is the same as displayed by *system_profiler SPDisplays* command under the section Graphics/Displays:.I have already considered using sysctl(), but I am unable to find proper hardware selector for graphics card in sysctl.h
任何建议都非常有用.
推荐答案
摆弄IOKit之后,我设法获取了所需的信息.可以在此处(原始来源)及以下版本:
After fiddling with IOKit I have managed to fetch the required information. The code can be seen here (original source)and below:
- (void)displayGraphicsInfo
{
// Get dictionary of all the PCI Devicces
CFMutableDictionaryRef matchDict = IOServiceMatching("IOPCIDevice");
// Create an iterator
io_iterator_t iterator;
if (IOServiceGetMatchingServices(kIOMasterPortDefault,matchDict,
&iterator) == kIOReturnSuccess)
{
// Iterator for devices found
io_registry_entry_t regEntry;
while ((regEntry = IOIteratorNext(iterator))) {
// Put this services object into a dictionary object.
CFMutableDictionaryRef serviceDictionary;
if (IORegistryEntryCreateCFProperties(regEntry,
&serviceDictionary,
kCFAllocatorDefault,
kNilOptions) != kIOReturnSuccess)
{
// Service dictionary creation failed.
IOObjectRelease(regEntry);
continue;
}
const void *GPUModel = CFDictionaryGetValue(serviceDictionary, @"model");
if (GPUModel != nil) {
if (CFGetTypeID(GPUModel) == CFDataGetTypeID()) {
// Create a string from the CFDataRef.
NSString *modelName = [[NSString alloc] initWithData:
(NSData *)GPUModel encoding:NSASCIIStringEncoding];
NSLog(@"GPU Model: %@", modelName);
[modelName release];
}
}
// Release the dictionary
CFRelease(serviceDictionary);
// Release the serviceObject
IOObjectRelease(regEntry);
}
// Release the iterator
IOObjectRelease(iterator);
}
}
这篇关于在目标C中获取图形卡信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!