Autenticación de la aplicación

El primer paso que debe realizar la aplicación es la autenticación. La autenticación comprueba la identidad de la aplicación en Windows Media Administrador de dispositivos. Una vez autenticada la aplicación, puede llamar a QueryInterface para obtener la interfaz IWMDeviceManager raíz, que se puede consultar para otras interfaces necesarias, que se pueden consultar para todas las demás interfaces. La autenticación solo se debe realizar una vez en el inicio.

Para autenticar la aplicación, realice estos pasos:

  1. CoCreate el objeto MediaDevMgr (id. de clase MediaDevMgr) y solicita una interfaz IComponentAuthenticate .
  2. Cree un objeto CSecureChannelClient para controlar la autenticación.
  3. Pase la clave de aplicación y transfiera el certificado al objeto de canal seguro. Puede usar la clave o el certificado ficticio que se muestra en el código de ejemplo siguiente para obtener la funcionalidad básica de las funciones del SDK. Sin embargo, para obtener toda la funcionalidad (importante para pasar archivos hacia y desde el dispositivo), debe solicitar una clave y un certificado de Microsoft, tal y como se describe en Herramientas para desarrollo.
  4. Pase la interfaz IComponentAuthenticate que creó en el paso 1 al objeto de canal seguro.
  5. Llame a CSecureChannelClient::Authenticate para autenticar la aplicación.
  6. Consulte IComponentAuthenticate para la interfaz IWMDeviceManager .

Estos pasos se muestran en el código de C++ siguiente.

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;
}

Creación de una aplicación de Administrador de dispositivos de Windows Media