2017-07-14 13 views
0

私はUSBマスストレージを見つけてPIDとVIDを取得するためにUSBデバイスを反復しようとしています。このため、私はIOUSBDeviceInterfaceについての参照を取得しようとしていますが、IOCreatePlugInInterfaceForServiceは、奇妙なエラーコード0x2C7 - "サポートされていない関数"で失敗します。誰かが教えてください、私は間違って何をしていますか?ここに私のコードは次のとおりです。USBデバイスに関する情報を取得する(OSX、C++)、IOCreatePlugInInterfaceForServiceが失敗する

#include <iostream> 
#include <IOKit/IOkitLib.h> 
#include <IOKit/usb/IOUSBLib.h> 
#include <IOKit/IOCFPlugIn.h> 
#include <IOKit/usb/USBSpec.h> 
#include <CoreFoundation/CoreFoundation.h> 

int main(int argc, const char * argv[]) 
{ 
CFMutableDictionaryRef matchingDictionary = NULL; 
io_iterator_t foundIterator = 0; 
io_service_t usbDevice; 
matchingDictionary = IOServiceMatching(kIOUSBDeviceClassName); 

IOServiceGetMatchingServices(kIOMasterPortDefault, matchingDictionary, &foundIterator); 

for(usbDevice = IOIteratorNext(foundIterator); usbDevice; usbDevice = IOIteratorNext(foundIterator)) 
{ 
    IOCFPlugInInterface** plugin = NULL; 
    SInt32 theScore=0; 
    IOReturn err; 
    err = IOCreatePlugInInterfaceForService(usbDevice, kIOUSBInterfaceUserClientTypeID, kIOCFPlugInInterfaceID, &plugin, &theScore); 
    if (err!= 0){ 
     //for all the devices (including Mass Storage), I get the same 
     //error: system 0x38 (IOKit), code: 0x2C7 (unsupported function) 
     std::cout<<"error, error code: "<<err_get_code(err) <<std::endl; 
    } 
    else if (plugin && *plugin) 
    { 
     //never happens 
     IOUSBDeviceInterface** usbInterface = NULL; 
     (*plugin)->QueryInterface(plugin, CFUUIDGetUUIDBytes(kIOUSBDeviceInterfaceID),(LPVOID*)&usbInterface); 
     (*plugin)->Release(plugin); 
     if (usbInterface && *usbInterface) 
     { 
      //other actions with usbInterface 
     }  

    } 

} 
IOObjectRelease(foundIterator); 
return 0; 
} 

答えて

1

あなたはIOUSBDeviceサービスに一致するが、IOUSBInterfaceUserClientに接続しようとしています。 IOUSBDeviceサービスに接続する場合は、ユーザークライアントタイプはkIOUSBDeviceUserClientTypeIDである必要があります。 IOUSBInterfaceUserClientが必要な場合は、IOUSBInterfaceサービスに一致する必要があります。

+0

はい、本当に!私の愚かな間違い、たくさんありがとう! –

関連する問題