Delen via


De toepassing verifiëren

De eerste stap die uw toepassing moet uitvoeren, is verificatie. Verificatie controleert de identiteit van de toepassing aan Windows Media Device Manager. Zodra u uw toepassing hebt geverifieerd, kunt u QueryInterface aanroepen om de hoofdinterface van IWMDevice Manager op te halen, die kan worden opgevraagd voor andere vereiste interfaces, die zelf kunnen worden opgevraagd voor alle andere interfaces. Verificatie hoeft slechts eenmaal plaats te vinden bij het opstarten.

Voer de volgende stappen uit om uw toepassing te verifiëren:

  1. CoCreate the MediaDevMgr object (klasse ID MediaDevMgr) en vraag een IComponentAuthenticate interface.
  2. Maak een CSecureChannelClient--object om de verificatie af te handelen.
  3. Geef uw toepassingssleutel door en draag het certificaat over aan het secure channel-object. U kunt de dummysleutel/het certificaat dat wordt weergegeven in de volgende voorbeeldcode gebruiken om basisfunctionaliteit van SDK-functies te verkrijgen. Als u echter volledige functionaliteit wilt krijgen (belangrijk voor het doorgeven van bestanden aan en van het apparaat), moet u een sleutel en certificaat van Microsoft aanvragen zoals beschreven in Tools for Development.
  4. Geef de IComponentAuthenticate interface die u in stap 1 hebt gemaakt door aan het beveiligde kanaalobject.
  5. Roep CSecureChannelClient::Authenticeer aan om uw toepassing te authenticeren.
  6. Voer query IComponentAuthenticate uit voor de IWMDeviceManager interface.

Deze stappen worden weergegeven in de volgende C++-code.

HRESULT CWMDMController::Authenticate()
{
    // Use a dummy key/certificate pair to allow basic functionality.
    // An authentic keypair is required for full SDK functionality.
    BYTE abPVK[] = {0x00};
    BYTE abCert[] = {0x00};
    HRESULT hr;
    CComPtr<IComponentAuthenticate> pAuth;

    // Create the WMDM object and acquire 
    // its authentication interface.
    hr = CoCreateInstance(
        __uuidof(MediaDevMgr),
        NULL,
        CLSCTX_INPROC_SERVER,
        __uuidof(IComponentAuthenticate),
        (void**)&pAuth);

    if (FAILED(hr)) return hr;

    // Create the secure channel client class needed to authenticate the application.
    // We'll use a global member variable to hold the secure channel client
    // in case we need to handle encryption, decryption, or MAC verification
    // during this session.
    m_pSAC = new CSecureChannelClient;
    if (m_pSAC == NULL) return E_FAIL;

    // Send the application's transfer certificate and the associated 
    // private key to the secure channel client.
    hr = m_pSAC->SetCertificate(
        SAC_CERT_V1,
        (BYTE *)abCert, sizeof(abCert),
        (BYTE *)abPVK,  sizeof(abPVK));
    if (FAILED(hr)) return hr;
            
    // Send the authentication interface we created to the secure channel 
    // client and authenticate the application with the V1 protocol.
    // (This is the only protocol currently supported.)
    m_pSAC->SetInterface(pAuth);
    hr = m_pSAC->Authenticate(SAC_PROTOCOL_V1);
    if (FAILED(hr)) return hr;

    // Authentication succeeded, so we can use WMDM.
    // Query for the root WMDM interface.
    hr = pAuth->QueryInterface( __uuidof(IWMDeviceManager), (void**)&m_IWMDMDeviceMgr);

    return hr;
}

Een Windows Media Device Manager-toepassing maken