IWMDRMProfileCollection::Item
![]() |
The Item method retrieves a specific DRM profile from the collection.
Syntax
HRESULT Item(
VARIANT var,
IWMDRMProfile** ppDRMProfile
);
Parameters
var
[in] VARIANT containing the index into the DRM profile collection or a specific DRM profile ID.
ppDRMProfile
[out] Pointer to a pointer to an IWMDRMProfile interface.
Return Values
If the method succeeds, it returns S_OK. If it fails, it supports the IErrorInfo interface and returns an HRESULT error code.
| Return code | Number | Description |
| E_POINTER | 0x80004003 | The indirect pointer to the DRM profile is NULL. |
Remarks
The input parameter is an index into the collection of DRM profiles, or a DRM profile ID. If you don't already know the index associated with DRM profile you want, iterate through the collection starting at item 0. On each iteration, increment the index and use the Item method to retrieve a pointer to each profile. Call the IWMDRMProfile::get_Name method to find the name of the current profile and compare the name retrieved to that needed. Exit the loop when a match is found.
Example Code
// Include libraries.
#include <windows.h>
#include <atlbase.h>
#include <comdef.h>
#include "C:\WMSDK\WMEncSDK9\include\wmencode.h"
#include "C:\WMSDK\WMEncSDK9\include\wmdrmprf.h" // for DRM features
HRESULT hr;
IWMEncoder2* pEncoder;
IWMDRMContentAuthor* pDRM;
IWMDRMProfileCollection* pDRMProColl;
IWMDRMProfile* pDRMPro;
IWMDRMAttributes* pProAttr;
// Initialize the COM library and retrieve a pointer
// to an IWMEncoder interface.
hr = CoInitialize(NULL);
if ( SUCCEEDED( hr ) )
{
hr = CoCreateInstance(CLSID_WMEncoder,
NULL,
CLSCTX_INPROC_SERVER,
IID_IWMEncoder2,
(void**) &pEncoder);
}
// Create an IWMDRMContentAuthor object.
if ( SUCCEEDED( hr ) )
{
hr = pEncoder->get_EncoderDRMContentAuthor(&pDRM);
}
// Retrieve the collection of DRM profiles.
if ( SUCCEEDED( hr ) )
{
hr = pDRM->get_DRMProfileCollection(&pDRMProColl);
}
// Declare variables. Specify the provider's Web site and signature values.
// The other variables are returned.
CComBSTR sPublicKey;
CComBSTR sWebURL("https://YourWebSite");
CComVariant vProfileID;
CComVariant vSeed;
CComBSTR sSigPrivKey("Replace with signature private key");
CComBSTR sSignedPubKey("Replace with signed public key");
CComBSTR sSigLSCert("Replace with the licensor certificate");
CComBSTR sSigRootCert("Replace with the Microsoft DRM License Server Root certificate");
// Create the DRM profile. The public key, DRM profile ID, and
// license key seed are returned.
if ( SUCCEEDED( hr ) )
{
hr = pDRM->CreateDRMProfile(sWebURL, sSigPrivKey, sSignedPubKey, sSigLSCert, sSigRootCert, &vProfileID, &vSeed, &sPublicKey);
}
// Create an IWMDRMProfile object and retrieve a profile.
CComVariant vIndex(0);
if ( SUCCEEDED( hr ) )
{
hr = pDRMProColl->Item(vIndex, &pDRMPro);
}
// Set the rest of the properties for the DRM profile.
if ( SUCCEEDED( hr ) )
{
hr = pDRMPro->put_Description(CComBSTR("Replace with a description of this DRM profile"));
}
if ( SUCCEEDED( hr ) )
{
hr = pDRMPro->put_LicenseAcquisitionURL(CComBSTR("Replace with v7 license acquisition URL"));
}
if ( SUCCEEDED( hr ) )
{
hr = pDRMPro->put_Name(CComBSTR("Replace with a name for the DRM profile"));
}
if ( SUCCEEDED( hr ) )
{
hr = pDRMPro->put_V1LicenseAcquisitionURL(CComBSTR("Replace with v1 license acquisition URL"));
}
// Add the individualization version as an attribute.
// This attribute should be saved in the DRM profile.
if ( SUCCEEDED( hr ) )
{
hr = pDRMPro->get_Attributes(&pProAttr);
}
if ( SUCCEEDED( hr ) )
{
hr = pProAttr->Add(CComBSTR("SECURITYVERSION"), CComVariant("2.2"));
}
// Add the content ID as an attribute. This attribute is for the current
// session only and is not saved in the profile.
if ( SUCCEEDED( hr ) )
{
hr = pDRM->get_Attributes(&pProAttr);
}
if ( SUCCEEDED( hr ) )
{
hr = pProAttr->Add(CComBSTR("ContentID"), CComVariant("10011"));
}
// Set the profile into the DRM session.
CComVariant vKeyID;
CComBSTR sProID;
if ( SUCCEEDED( hr ) )
{
hr = pDRMPro->get_ID(&sProID);
}
if ( SUCCEEDED( hr ) )
{
hr = pDRM->SetSessionDRMProfile(sProID, &vKeyID);
}
// Release pointers.
if ( pDRM )
{
pDRM->Release();
pDRM = NULL;
}
if ( pDRMProColl )
{
pDRMProColl->Release();
pDRMProColl = NULL;
}
if ( pDRMPro )
{
pDRMPro->Release();
pDRMPro = NULL;
}
if ( pProAttr )
{
pProAttr->Release();
pProAttr = NULL;
}
if ( pEncoder )
{
pEncoder->Release();
pEncoder = NULL;
}
Requirements
Header: wmdrmprf.h
Library: wmenc.exe
See Also
.gif)