banner art

Previous Next


This server calls the GetDataContainerVersion method to retrieve version information about cached content.


  HRESULT GetDataContainerVersion(
  IWMSCommandContext*  pCommandContext,
  IWMSContext*  pUserContext,
  IWMSContext*  pPresentContext,
  LPWSTR  pszContainerName,
  DWORD  dwFlags,
  IWMSDataSourcePluginCallback*  pCallback,
  QWORD  qwContext



[in] Pointer to an IWMSCommandContext interface that specifies the command context.


[in] Pointer to an IWMSContext interface that specifies the user context.


[in] Pointer to an IWMSContext interface that specifies the presentation context.


[in] Pointer to a null-terminated string containing the container name.


[in] DWORD containing the flags. Set to NULL. Reserved for future use.


[in] Pointer to an IWMSDataSourcePluginCallback interface. The plug-in calls IWMSDataSourcePluginCallback::OnGetDataContainerVersion to return a result to the server.


[in] QWORD containing a value defined by the server to identify which GetDataContainerVersion request the plug-in is responding to when it calls IWMSDataSourcePluginCallback::OnGetDataContainerVersion. The plug-in must pass this value back unaltered.

Return Values

If the method succeeds, the plug-in must return S_OK. To report an error, the plug-in can return any HRESULT other than S_OK. If the plug-in uses the IWMSEventLog interface to log error information directly to the Windows Event Viewer, it is recommended that it return NS_E_PLUGIN_ERROR_REPORTED. Typically, the server attempts to make plug-in error information available to the server object model, the Windows Event Viewer, and the troubleshooting list in the details pane of the Windows Media Services MMC. However, if the plug-in uses the IWMSEventLog interface to send custom error information to the Windows Event Viewer, returning NS_E_PLUGIN_ERROR_REPORTED stops the server from also logging to the event viewer. For more information about retrieving plug-in error information, see Identifying Plug-in Errors.


The data source plug-in must set information about the data container into an IWMSDataContainerVersion interface. It returns a pointer to this interface when it calls IWMSDataSourcePluginCallback::OnGetDataContainerVersion.

Example Code

The following example illustrates a possible implementation of GetDataContainerVersion for an NTFS data source plug-in.

// Used to specify an expiration time.
#define DBL_MAX         1.7976931348623158e+308

                    IWMSCommandContext *pCommandContext,
                    LPWSTR pszContainerName,
                    DWORD dwFlags,
                    IWMSDataSourcePluginCallback *pCallback,
                    QWORD qwContext
    // Declare variables.
    HRESULT hr = S_OK;
    DATE dateOriginLastModifiedTime;
    WIN32_FILE_ATTRIBUTE_DATA FileAttributeData;
    SYSTEMTIME stLastModifiedTime;
    IWMSDataContainerVersion *pVersion = NULL;
    LPWSTR pszHost;
    LPWSTR pszPath;
    DWORD dwLength;
    QWORD qwFileSize;
    BSTR bstrFileSize = NULL;
    WCHAR pszFileSize[64];

    // Parse the URL to get the path identifying a location on
    // the hard disk. The DecodeUrl function is user-defined.
    dwLength = wcslen( pszContainerName ) + 1;
    pszHost = (LPWSTR) _alloca( dwLength * sizeof( WCHAR ) );
    pszPath = (LPWSTR) _alloca( dwLength * sizeof( WCHAR ) );
    hr = DecodeUrl( pszContainerName, pszHost, dwLength,
                    pszPath, dwLength );
    if (FAILED(hr)) goto EXIT;

    // Retrieve file information.
    GetFileAttributesEx( pszPath, GetFileExInfoStandard,
                         &FileAttributeData )

    // Convert the last modified time from FILETIME to DATE format.
    FileTimeToSystemTime( &FileAttributeData.ftLastWriteTime, 
                          &stLastModifiedTime );
    SystemTimeToVariantTime( &stLastModifiedTime, 
                             &dateOriginLastModifiedTime );

    // Create an IWMSDataContainerVersion object.
    hr = m_pClassFactory->CreateInstance( IID_IWMSDataContainerVersion,
                                         (void **) &pVersion );
    if (FAILED(hr)) goto EXIT;

    // Specify the last modified time.
    hr = pVersion->SetLastModifiedTime( dateOriginLastModifiedTime );
    if (FAILED(hr)) goto EXIT;

    // Specify that the content never expires.
    hr = pVersion->SetExpirationTime( (double) DBL_MAX );
    if (FAILED(hr)) goto EXIT;

    // Specify the cache flags.
    hr = pVersion->SetCacheFlags( 0xffffffff );
    if (FAILED(hr)) goto EXIT;

    // Specify the size of the content in bytes.
    hr = pVersion->SetContentSize( FileAttributeData.nFileSizeLow,
                                   FileAttributeData.nFileSizeHigh );
    if (FAILED(hr)) goto EXIT;

    // Specify an entity tag. The tag can be any string. In this example,
    // it is a string containing the file size. There can be multiple tags.
    qwFileSize = MAKEQWORD( FileAttributeData.nFileSizeLow,
                            FileAttributeData.nFileSizeHigh );
    _ui64tow( qwFileSize, (LPWSTR) pszFileSize, 10 );
    bstrFileSize = SysAllocString( (LPWSTR) pszFileSize );
    hr = pVersion->SetEntityTag( bstrFileSize );
    if (FAILED(hr)) goto EXIT;

    // Return to the server a pointer to the 
    // IWMSDataContainerVersion interface. 
    hr = pCallback->OnGetDataContainerVersion( hr, pVersion, qwContext );
    hr = S_OK;
    // TODO: Release temporary objects.
    return( hr );


Header: datacontainer.h.

Library: WMSServerTypeLib.dll.

Platform: Windows Server 2003, Enterprise Edition; Windows Server 2003, Datacenter Edition; Windows Server 2008.

See Also

Previous Next