IWMSDataSourcePlugin::GetRootDirectories
.gif)
| Previous | Next |
IWMSDataSourcePlugin::GetRootDirectories
The server calls the GetRootDirectories method to retrieve the physical paths of the root directories associated with a data container.
Syntax
HRESULT GetRootDirectories( LPWSTR* pstrRootDirectoryList, DWORD dwMaxRoots, IWMSDataSourcePluginCallback* pCallback, QWORD qwContext );
Parameters
pstrRootDirectoryList
[in] Pointer to an array of strings to be filled with the root directory paths.
dwMaxRoots
[in] DWORD containing the maximum number of root directories.
pCallback
[in] Pointer to an IWMSDataSourcePluginCallback interface. The plug-in calls IWMSDataSourcePluginCallback::OnGetRootDirectories to return a result to the server.
qwContext
[in] QWORD containing a value defined by the server to identify which GetRootDirectories request the plug-in is responding to when it calls IWMSDataSourcePluginCallback::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
The following example illustrates a possible implementation of GetRootDirectories for an NTFS data source plug-in.
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 |