CWebStorage::EnumObjects Method  
 
BOOL EnumObjects(
  LPCTSTR lpszMatchLabel,  
  LPCTSTR lpszContentType,  
  LPWEB_STORAGE_OBJECT& lpObjects,  
  DWORD& dwObjects  
);
DWORD EnumObjects(
  LPCTSTR lpszMatchLabel,  
  LPCTSTR lpszContentType  
);

The EnumObjects method enumerates all storage objects that match the specified label or content type.

Parameters

lpszMatchLabel
A null-terminated string which specifies the value to match against the object labels in the container. The string may contain wildcard characters similar to those use with the Windows filesystem. A "?" character matches any single character, and "*" matches any number of characters in the label. If this value is a NULL pointer or an empty string, all objects in the container will be matched.
lpszContentType
A null-terminated string which specifies the content type of the objects to be enumerated. If this value is a NULL pointer or an empty string, the content type is ignored and all matching objects are returned.
lpObjects
A pointer to an array of WEB_STORAGE_OBJECT structures that will contain information about the enumerated objects. If this parameter is NULL, then no object information is returned.
lpdwObjects
A pointer to an unsigned integer that will contain the number of objects enumerated by this method. If the lpObjects parameter points to an array of WEB_STORAGE_OBJECT structures, this parameter must be initialized to the maximum size of the array being passed to the method. If the lpObjects parameter is NULL, this value must be initialized to zero, and when the method returns it will contain the number of matching objects.

Return Value

If the method succeeds, the return value is non-zero. If the method fails, the return value is zero. To get extended error information, call the GetLastError method.

Remarks

The EnumObjects method can be used to enumerate the number of objects that match a given label, content type or both. If a content type is specified, it must be a valid MIME media content type designated using the type/subtype nomenclature. For example, "text/plain" or "image/jpeg". An invalid MIME type will cause the method to fail.

This method can be used in two ways. If the lpObjects parameter is NULL and the value passed by reference in the lpdwObjects parameter is initialized to zero, the method will return the number of matching objects in lpdwObjects. This can be used to dynamically determine the size of the lpObjects array instead of declaring a fixed-size array in your application.

If the lpObjects parameter is not NULL, then the value referenced by lpdwObjects must be initialized to the maximum size of the array that lpObjects points to. It is important to note that if either parameter is not initialized correctly, it can result in memory corruption and/or an unhandled exception.

There is an alternative version of EnumObjects which only returns a count of objects that match the specified content type and/or object label name, without returning information about the objects. This can be used to determine how many objects match the given criteria prior to requesting the object metadata.

The GetFirstObject and GetNextObject methods can be used to iterate through all matching storage objects without allocating memory to store all of the matching objects. Using GetFirstObject and GetNextObject is more efficient when the container contains a large number of objects that match the specified label and/or content type.

Example

DWORD dwObjects = 0;
LPWEB_STORAGE_OBJECT lpObjects = NULL;

if (pStorage->EnumObjects(_T("*.pdf"), NULL, lpObjects, dwObjects))
{
    // Print information about each object
    for (DWORD dwIndex = 0; dwIndex < dwObjects; dwIndex++)
    {
        _tprintf(_T("Object: %s\n"), lpObjects[dwIndex].szObjectId);
        _tprintf(_T("Label: %s\n"), lpObjects[dwIndex].szLabel);
        _tprintf(_T("Size: %lu\n"), lpObjects[dwIndex].dwObjectSize);
        _tprintf(_T("Digest: %s\n"), lpObjects[dwIndex].szDigest);
        _tprintf(_T("Content: %s\n"), lpObjects[dwIndex].szContent);

        if (dwObjects > 1 && dwIndex < dwObjects - 1)
            _tprintf(_T("\n"));
    }
}

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cstools12.h
Import Library: cswebv12.lib
Unicode: Implemented as Unicode and ANSI versions

See Also