Share via


To Use IComponentAuthenticate with an Application

banner art
  1. Include Sac.h and Scclient.h.

  2. Link to Mssachlp.lib.

  3. Add the Keys.c file that you received when you signed the license agreement for your project.

  4. Declare a CSecureChannelClient object. This object must be available to any routines that call Windows Media Device Manager. For example, if your application has only a single code path, the CSecureChannelClient object can be a local variable, but if you have a user interface and several code paths, it must be a global object.

  5. Call CoCreateInstance to create an IComponentAuthenticate interface. Then insert code similar to the following example:

        HRESULT hr = E_FAIL;
        IComponentAuthenticate *pAuth = NULL;
        CSecureChannelClient SAC;
    
    // Insert error checking and log reporting.
        hr = CoCreateInstance(CLSID_MediaDevMgr, 
                              NULL, 
                              CLSCTX_INPROC_SERVER,
                              IID_IComponentAuthenticate,
                              (void**)&pAuth);
        if (SUCCEEDED(hr))
        {
            hr = SAC.SetCertificate( (BYTE*)abCert, 
                                    sizeof(abCert),
                                    (BYTE*)abPVK, 
                                    sizeof(abPVK) );
            if (FAILED(hr))
                goto exit;
            SAC.SetInterface(pAuth);  // The return value is void.
    
            hr = pAuth.SACGetProtocols(&pdwProtocols, 
                                       &dwProtocolCount);
            if(pdwProtocols)
                CoTaskMemFree(pdwProtocols);
            hr = SAC.Authenticate(SAC_PROTOCOL_V1);
            if ( FAILED(hr) )
                goto exit;
    
    // Get main interface to Windows Media Device Manager.
            hr = pAuth->QueryInterface(IID_IWMDeviceManager,
                                       (void**)&pDevMgr);
            pAuth.Release();
            if (FAILED(hr))
                goto exit;
                return S_OK;
        }
    

See Also