Share via


IWMSDataSourcePluginCallback::OnGetDataContainerVersion

banner art

Previous Next

IWMSDataSourcePluginCallback::OnGetDataContainerVersion

The OnGetDataContainerVersion method is called by a data source plug-in to respond when the server calls IWMSDataSourcePlugin::GetDataContainerVersion.

Syntax

  HRESULT OnGetDataContainerVersion(
  HRESULT  hr,
  IWMSDataContainerVersion*  pVersion,
  QWORD  qwContext
);

Parameters

hr

[in] HRESULT containing the result of the call to IWMSDataSourcePlugin::GetDataContainerVersion.

pVersion

[in] Pointer to an IWMSDataContainerVersion interface created when the plug-in implemented IWMSDataSourcePlugin::GetDataContainerVersion.

qwContext

[in] QWORD containing a value defined by the server to identify which IWMSDataSourcePlugin::GetDataContainerVersion request the plug-in is responding to when it calls 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.

Example Code

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

CDataSourcePlugin::GetDataContainerVersion( 
                    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;
    
EXIT:
    // TODO: Release temporary objects.
    return( hr );
}

Requirements

Header: datacontainer.h.

Library: WMSServerTypeLib.dll.

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

See Also

Previous Next