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.
DWORD dwObjects = 0;
LPWEB_STORAGE_OBJECT lpObjects = NULL;
if (pStorage->EnumObjects(_T("*.pdf"), NULL, lpObjects, dwObjects))
{
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"));
}
}