IWMSDataSourcePluginCallback::OnGetRootDirectories

banner art

Previous Next

IWMSDataSourcePluginCallback::OnGetRootDirectories

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

Syntax

  HRESULT OnGetRootDirectories(
  HRESULT  hr,
  DWORD  dwNumReturnedRoots,
  DWORD  dwTotalNumRoots,
  QWORD  qwContext
);

Parameters

hr

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

dwNumReturnedRoots

[in] DWORD containing the number of root directories returned.

dwTotalNumRoots

[in] DWORD containing the total number of root directories.

qwContext

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

HRESULT STDMETHODCALLTYPE 
CDataSourcePlugin::GetRootDirectories( 
                        LPWSTR *pstrRootDirectoryList,
                        DWORD dwMaxRoots,
                        IWMSDataSourcePluginCallback *pCallback,
                        QWORD qwContext
                        )
{
    HRESULT hr = S_OK;
    DWORD dwRootNum = 0;
    DWORD dwTotalNumRoots = 0;
    DWORD dwBufferSize = 0;
    WCHAR tempBuffer[3];
    WCHAR *pFullBuffer = NULL;
    WCHAR *pEndBuffer;
    WCHAR *pStartPath;
    WCHAR *pStopPath;
    WCHAR *pstrFile;
    DWORD dwPathNameLength;
    DWORD dwIndex;

    // Determine the size of a temporary buffer.
    dwBufferSize = GetLogicalDriveStringsW( 1, tempBuffer );

    // Allocate the buffer.
    pFullBuffer = new WCHAR[ dwBufferSize + 2 ];

    // Fill the buffer with strings that contain valid system drives.
    dwBufferSize = GetLogicalDriveStringsW( dwBufferSize, pFullBuffer );

    // Loop through the buffer to extract the paths.
    pStartPath = pFullBuffer;
    pEndBuffer = pFullBuffer + dwBufferSize;
    dwRootNum = 0;
    dwTotalNumRoots = 0;
    while ( pStartPath < pEndBuffer )
    {
        // Find the end of the current path as indicated by the
        // NULL character.
        pStopPath = pStartPath;
        while ( ( *pStopPath ) && ( pStopPath < pEndBuffer ) )
        {
            pStopPath++;
        }

        // If you found a non-empty path, record it.
        if( pStopPath > pStartPath )
        {
            if( dwRootNum < dwMaxRoots )
            {
                dwPathNameLength = pStopPath - pStartPath;
                pstrFile = (LPWSTR) CoTaskMemAlloc( sizeof(WCHAR) * 
                           ( dwPathNameLength + URL_SCHEME_LENGTH + 2 ) );

                wcscpy_s( pstrFile, 
                           dwPathNameLength + URL_SCHEME_LENGTH + 2,
                           URL_SCHEME );
                wcscpy_s( pstrFile + URL_SCHEME_LENGTH,
                           dwPathNameLength + 2, pStartPath );

                // Copy the root path to the string array.
                pstrRootDirectoryList[dwRootNum] = pstrFile;

                dwRootNum++;
            } 

            dwTotalNumRoots++;
        } 

        // The next path starts just after the previous path.
        pStartPath = pStopPath + 1;
        if( ( NULL == *pStartPath ) || ( pStartPath >= pEndBuffer ) )
        {
            break;
        }
    } 

    ( void ) pCallback->OnGetRootDirectories( 
                            hr,
                            dwRootNum,
                            dwTotalNumRoots,
                            qwContext
                            );

    // TODO: Free any allocated memory.

    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