Adding Users, Rights, and Other Information to a License
After creating an issuance license, you can add users and rights to it. Note that rights are case-sensitive: You should add the EDIT right, not the Edit right.
Note The owner specified by hOwner in DRMCreateIssuanceLicense is the Owner principal, not the OWNER right. Merely specifying someone as the hOwner in DRMCreateIssuanceLicense does not grant them the OWNER right; granting yourself (or anyone else) the OWNER right must be done explicitly by using DRMAddRightWithUser. Zero, one, or more users can be granted the OWNER right, which never expires. For more information, see the hOwner parameter of DRMCreateIssuanceLicense.
The following example shows how to create a user and an EDIT right, and how to grant that EDIT right to the user.
int AddMetadata(DRMPUBHANDLE* phIssuanceLicense)
{
HRESULT hr = S_OK;
// Create a user.
hr = DRMCreateUser(
L"someone@example.com", // user name
L"MyID" // user ID
L"Windows", // type of user ID
&hUser // user object handle
);
if( FAILED( hr ) )
goto e_Exit;
// Create a right for the user.
hr = DRMCreateRight(
L"EDIT", // name of the right
&stTimeFrom, // beginning validity time
&stTimeUntil, // ending validity time
0, // count of extended elements
NULL, // extended information name
NULL, // extended information value
&hRight // rights object handle
);
if( FAILED( hr ) )
goto e_Exit;
// Add the right and user to the license.
hr = DRMAddRightWithUser(
*phIssuanceLicense, // issuance license handle
hRight, // handle of right to add
hUser ); // handle of user to add
if( FAILED( hr ) )
goto e_Exit;
// Add metadata to the license.
// Create a GUID to use as a unique content ID.
hr = CoCreateGuid( &guid );
if( FAILED( hr ) )
goto e_Exit;
wszGUID = new WCHAR[ GUID_STRING_LENGTH ];
if( NULL == wszGUID )
goto e_Exit;
uiGUIDLength = StringFromGUID2(
guid,
wszGUID,
GUID_STRING_LENGTH );
if( 0 == uiGUIDLength )
{
hr = E_FAIL;
goto e_Exit;
}
// Set the content ID in the issuance license.
hr = DRMSetMetaData(
*phIssuanceLicense, // issuance license handle
wszGUID, // content ID
L"MS-GUID", // type of content ID
NULL, // optional SKU ID
NULL, // SKU ID type
NULL, // content type
NULL // content name
);
if( FAILED( hr ) )
goto e_Exit;
e_Exit:
return hr;
}
After you create an issuance license and add users and rights to it, you can add other information to it as well:
- To add name-value pairs that contain custom values, use the DRMSetApplicationSpecificData function. This data can be used by a consuming application to perform many tasks.
- To add names and descriptions of the license in multiple human languages, use the DRMSetNameAndDescription function.
- To add a revocation point, use the DRMSetRevocationPoint function. A revocation point is a location where an application can download a revocation list that describes users, machine certificates, and many other principals that should be prevented from using a use license.
- To add restrictions on what applications must or cannot use this license, use DRMSetUsagePolicy.
See Also
Licenses and Certificates
Building a Publishing Application
Send comments about this topic to Microsoft
Build date: 3/13/2008