none
IWMDeviceManager3,IWMDMEnumDevice ---系统无法识别MTP设备?? RRS feed

  • 问题

  •  

    HRESULT hr;
        CComPtr<IComponentAuthenticate> pAuth = NULL;
        IWMDeviceManager3 * pIWMDevMgr3 = NULL;
        IWMDMEnumDevice *pEnumDevice = NULL;
        // Initialize member variables
        m_pSAC        = NULL;
        m_pWMDevMgr   = NULL;
        m_pWmdmDevice = NULL;
        //
        // Acquire the authentication interface of WMDM
        //
        hr = CoCreateInstance(
            CLSID_MediaDevMgr,
            NULL,
            CLSCTX_INPROC_SERVER,
            IID_IComponentAuthenticate,
            (void**)&pAuth
        );
        ExitOnFail( hr );
        // Create the client authentication object
        m_pSAC = new CSecureChannelClient;
        ExitOnNull( m_pSAC );
        //
        // Select the cert and the associated private key into the SAC
        //
        hr = m_pSAC->SetCertificate(
            SAC_CERT_V1,
            (BYTE *)abCert, sizeof(abCert),
            (BYTE *)abPVK,  sizeof(abPVK)
        );
        ExitOnFail( hr );
        //
        // Select the authentication interface into the SAC
        //
        m_pSAC->SetInterface( pAuth );
        //
        // Authenticate with the V1 protocol
        //
        hr = m_pSAC->Authenticate( SAC_PROTOCOL_V1 );
        ExitOnFail( hr );
        //
        // Authenticate succeeded, so we can use the WMDM functionality.
        // Acquire an interface to the top-level WMDM interface.
        //
        hr = pAuth->QueryInterface( IID_IWMDeviceManager, (void**)&m_pWMDevMgr );
        ExitOnFail( hr );
        hr = m_pWMDevMgr->QueryInterface (IID_IWMDeviceManager3, (void**) &pIWMDevMgr3);
        if (SUCCEEDED (hr))
        {
            hr = pIWMDevMgr3->EnumDevices2(&pEnumDevice);
            pIWMDevMgr3->Release();
        }
        ExitOnFail( hr );
        while( TRUE )
        {
            IWMDMDevice *pWmdmDevice;
            ULONG        ulFetched;
            WCHAR       szManufacturer[128];
            hr = pEnumDevice->Next( 1, &pWmdmDevice, &ulFetched );
    ///hr得到失败的值,没有找到MTP设备????执行到这里执行不下去了
    。。。。。。。。。。。。
    #define ExitOnFail( hr )    if ( FAILED(hr) ) goto lExit;

    这段代码是从别的程序(是OK的)里提取出来的

    ///急!!!!!!!!!!!!!!!!不知道还要加些什么东东
    2008年11月20日 16:53