รับข้อมูลกราฟิกการ์ดในวัตถุประสงค์ C

ฉันต้องการรับข้อมูลกราฟิกการ์ดในแอปพลิเคชันของฉัน ข้อมูลที่ฉันต้องการเหมือนกับที่แสดงโดยคำสั่ง *system_profiler SPDisplays* ใต้ส่วน กราฟิก/การแสดงผล: ฉันได้พิจารณาใช้ sysctl() แล้ว แต่ไม่พบตัวเลือกฮาร์ดแวร์ที่เหมาะสมสำหรับกราฟิกการ์ดใน sysctl.h

ข้อเสนอแนะใด ๆ ที่เห็นคุณค่าอย่างมาก


person rsharma    schedule 06.08.2013    source แหล่งที่มา
comment
คุณควรใช้ IOKit แทน sysctl: นักพัฒนา .apple.com/library/mac/#documentation/devicedrivers/   -  person Macmade    schedule 06.08.2013
comment
ขอบคุณสำหรับคำแนะนำ @Macmade ฉันจะเริ่มต้นด้วย IOKit ทันที   -  person rsharma    schedule 06.08.2013


คำตอบ (1)


หลังจากเล่นซอกับ IOKit ฉันก็สามารถดึงข้อมูลที่ต้องการได้ สามารถดูโค้ดได้ที่นี่ (แหล่งที่มาดั้งเดิม)และด้านล่าง:

- (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);
    }
}
person rsharma    schedule 07.08.2013
comment
โปรดรวมโค้ดจากเว็บไซต์ของคุณซึ่งขณะนี้ใช้งานไม่ได้ (โปรดดูของคุณ คำตอบอยู่ในปราสาทอื่น: เมื่อใดที่คำตอบไม่ใช่คำตอบ?) - person Dan Clarke; 05.11.2015
comment
สวัสดี @rsharma! ฉันได้ส่งฉบับไปยังคำตอบของคุณเพื่อรวมรหัสจากลิงก์นั้นเพื่อให้คำตอบของคุณยังคงใช้ได้แม้ว่าเจ้าของไซต์จะปิดตัวลงก็ตาม - person NSNoob; 13.11.2015
comment
ใช่แล้ว ดูเหมือนว่าโค้ดนี้มาจาก ที่นี่ โดยไม่มีการระบุแหล่งที่มา - person trojanfoe; 13.11.2015
comment
@trojanfoe ใช่อาจจะเป็น เป็นโพสต์เก่าที่ฉันสร้างขึ้นและฉันอาจพลาดที่จะอ้างอิงถึงแหล่งที่มา ฉันจะทำมันทันที (และคำตอบด้วย) - person rsharma; 13.11.2015