Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The OnOpenDirectory method is called by a data source plug-in to respond when the server calls IWMSDataSourcePlugin::OpenDirectory.
HRESULT OnOpenDirectory(
HRESULT hr,
IWMSDirectory* pDirectory,
QWORD qwContext
);
Arguments
hr |
[in] HRESULT containing the result of the call to IWMSDataSourcePlugin::OpenDirectory. |
pDirectory |
[in] Pointer to an IWMSDirectoryIWMSDirectory Interface that contains information about the subdirectories and media files in the directory. |
qwContext |
[in] QWORD containing a value defined by the server to identify which IWMSDataSourcePlugin::OpenDirectory request the plug-in is responding to when it calls OnOpenDirectory. The plug-in must pass this value back unaltered. |
Return Value
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 IWMSEventLogIWMSEventLog 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
The OnOpenDirectory method is called near the end of the following example to send a pointer to an IWMSDirectory IWMSDirectory Interface to the server. The CDirectory class is user-defined and implements the IWMSDirectory interface.
CDirectory::Initialize(
IWMSContext *pUserContext,
LPWSTR pszContainerName,
CNTFSStorageSystem *pOwnerStorageSystem,
IWMSDataSourcePluginCallback *pCallback,
QWORD qwContext
)
{
HRESULT hr = S_OK;
HRESULT hr = S_OK;
WCHAR *pszNtfsPathname;
size_t sFileName;
DWORD dwFileAttributes;
DWORD dwIndex;
HANDLE hFileEnum = INVALID_HANDLE_VALUE;
BOOL fSuccess = FALSE;
WIN32_FIND_DATA FileInfo;
// Parse the path name to remove the scheme type and
// use the GetFileAttributes() function to determine
// whether the path identifies a directory.
pszNtfsPathname = pszContainerName + URL_SCHEME_LENGTH;
dwFileAttributes = GetFileAttributes( pszNtfsPathname );
if( !( FILE_ATTRIBUTE_DIRECTORY & dwFileAttributes ) )
{
hr = HRESULT_FROM_WIN32( ERROR_DIRECTORY );
}
// Add the global wildcard character '*' to the end
// of the directory name.
sFileName = wcslen( pszNtfsPathname );
pSearchDirName = new WCHAR[ sFileName + 8 ];
pSearchDirName[sFileName] = '*';
pSearchDirName[sFileName + 1] = '\0';
// Find the first entry in the directory.
hFileEnum = FindFirstFileW( m_pSearchDirName, &FileInfo );
dwIndex = 0;
fSuccess = TRUE;
while ( TRUE )
{
// TODO: Determine whether you have reached the end
// of the directory items. If so, break.
// If the directory item is empty or '.' or '..' or
// a hidden file, skip it, grab the next file and
// start the loop again.
if( ( '\0' == FileInfo.cFileName[0] )
|| ( ( '.' == FileInfo.cFileName[0] )
&& ('\0' == FileInfo.cFileName[1] ) )
|| ( ( '.' == FileInfo.cFileName[0] )
&& ( '.' == FileInfo.cFileName[1] )
&& ( '\0' == FileInfo.cFileName[2] ) )
|| ( FileInfo.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN ) )
{
fSuccess = FindNextFileW( hFileEnum, &FileInfo );
continue;
}
// TODO: Retrieve information about each file, such as
// the name and size, and save it in a linked list of
// user-defined CDirectoryInfo objects.
// In this example, the CDirectoryInfo class contains
// four data members that save information about a file:
// CDirectoryInfo()
// {
// m_cRef = 1; // Reference count.
// m_pszwName = NULL; // File name.
// m_qwSize = 0; // File size.
// m_pNext = NULL; // Pointer to next CDirectoryInfo.
// }
// Increment the index and find the next file.
dwIndex++;
fSuccess = FindNextFileW( hFileEnum, &FileInfo );
}
// Callback to the server.
hr = pCallback->OnOpenDirectory( hr, this, qwContext );
// Because errors are passed through the callback, return S_OK.
return( S_OK );
}
Requirements
Header: datacontainer.h.
Library: WMSServerTypeLib.dll.
Platform: Windows Server 2003, Enterprise Edition; Windows Server 2003, Datacenter Edition; Windows Server 2008.