To Use IComponentAuthenticate with an Application
Include Sac.h and Scclient.h.
Link to Mssachlp.lib.
Add the Keys.c file that you received when you signed the license agreement for your project.
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.
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