Partager via


IWMDRMDeviceApp::GenerateMeterChallenge

banner art

The GenerateMeterChallenge method acquires metering data from a device.

Syntax

HRESULT GenerateMeterChallenge(IWMDMDevice*pDevice,BSTRbstrMeterCert,BSTR*pbstrMeterURL,BSTR*pbstrMeterData);

Parameters

pDevice

[in]  Pointer to an IWMDMDevice interface. If the application passes in NULL, metering information stored on the computer is used instead of metering information from a connected device.

bstrMeterCert

[in]  The application's metering certificate, as a BSTR. This is a signed certificate received from Microsoft.

pbstrMeterURL

[out]  The URL where metering data should be sent. This is allocated by Windows Media Device Manager, and must be free by the caller using SysFreeString.

pbstrMeterData

[out]  Metering data to send to the metering service. This is allocated by Windows Media Device Manager, and must be free by the caller using SysFreeString.

Return Values

The method returns an HRESULT. Possible values include, but are not limited to, those in the following table.

Return code Description
S_OK The method succeeded.
DRM_E_INVALIDARG One or more arguments are not valid.
DRM_E_INVALIDXMLTAG XML is improperly formed.
DRM_E_NOXMLCLOSETAG XML is improperly formed.
DRM_E_NOXMLOPENTAG XML is improperly formed.
DRM_E_XMLNOTFOUND Failed to find a required XML tag.
Errors from the device Any of a number of device errors.
Errors from the DRM Client Any of a number of internal DRM client errors.
NS_E_DEVICE_NOT_WMDRM_DEVICE The specified device is not a Windows Media DRM–compatible device.

Remarks

Before calling this method, the application should call IWMDRMDeviceApp::QueryDeviceStatus or IWMDRMDeviceApp2::QueryDeviceStatus2 to verify that all the device's DRM components are up to date. This method can only be called on a device that supports Windows Media DRM 10 for Portable Devices.

The retrieved data pbstrMeterData should be sent to the URL specified by pbstrMeterURL. Be sure to URL-encode the retrieved data so that it does not get modified during transfer.

See Handling Protected Content in the Application for more information.

Example Code

The following C++ code example creates a WMDRMDeviceApp object, verifies that the device is a Windows Media DRM 10 device, that its clock is accurate, and then requests the metering data.

HRESULT hr = S_OK;
// Create the WMDRMDeviceApp object.
CComPtr<IWMDRMDeviceApp> pDRM;
hr = pDRM.CoCreateInstance(CLSID_WMDRMDeviceApp, 0, CLSCTX_ALL);

// Find out first if the device is a WMDRM 10 device, and if it requires
// any clock updates.
DWORD status = 0;
hr = pDRM->QueryDeviceStatus(pDevice, &status);

if (!(WMDRM_DEVICE_ISWMDRM & status)) // Device is not WMDRM 10. Nothing can be updated,
    return E_FAIL;                   // and metering cannot be performed.
else if (status & WMDRM_DEVICE_REVOKED) // Device is revoked.
    return E_FAIL;
else if (status & WMDRM_DEVICE_NEEDCLOCK || 
    status & WMDRM_CLIENT_NEEDINDIV ||
    status & WMDRM_DEVICE_REFRESHCLOCK)
{
    // Need to update device clock. 
    // Using custom function, which is synchronous.
    hr = myAcquireDeviceData(pDRM, pDevice, this, status, &result);
    if (hr != S_OK || result != 0)    // Couldn't perform the updates.
        return E_FAIL;    
}

// Any updates have been performed. Now get the metering information from the device.
CComBSTR meterCert(METERCERT);
CComBSTR URL;
CComBSTR rawdata;
CComBSTR data;
hr = pDRM->GenerateMeterChallenge(pDevice, meterCert, &URL, &rawdata);
if (hr == S_OK)
    ..... Send to URL...

Requirements

Header: Requires both WMDRMDeviceApp.h and wmdrmdeviceapp_i.c (built from WMDRMDeviceApp.idl).

Library: mssachlp.lib

See Also