Function : Views; Folders

NIFReadEntries - Reads information about entries in a collection.
----------------------------------------------------------------------------------------------------------

#include <nif.h>

STATUS LNPUBLIC NIFReadEntries(
HCOLLECTION hCollection,
COLLECTIONPOSITION far *IndexPos,
WORD SkipNavigator,
DWORD SkipCount,
WORD ReturnNavigator,
DWORD ReturnCount,
DWORD ReturnMask,
DHANDLE far *rethBuffer,
WORD far *retBufferLength,
DWORD far *retNumEntriesSkipped,
DWORD far *retNumEntriesReturned,
WORD far *retSignalFlags);

Description :

This function scans a collection and returns information about the entries in the collection.

The function takes as input a collection (parameter 1) and a starting location in the collection (parameter 2). The function skips some number of entries (possibly zero), based on parameters 3 and 4. After skipping some entries, the function begins reading the entries in the collection, based on parameters 5, 6 and 7. Parameters 5 and 6 specify how to navigate the collection while reading, and parameter 7 specifies what information to return about each entry in the collection.

The information is returned in a buffer (parameter 8). All the information about the first entry appears first in the buffer, all the information about the second entry appears next and so on. Within each entry, the information occurs in the order of the bits in the bit flags READ_MASK_xxx.

After a call to NIFReadEntries(), the collection position (parameter 2) points to the last entry read. You can use repeated calls to NIFReadEntries to move incrementally through a collection. However, upon repeating the call to NIFReadEntries(), use one of the NAVIGATE_NEXT_xxx skip navigate flags (the third parameter) and use a skip count of 1L (the fourth parameter) to advance the collection position past the last one read so that it begins reading with the next entry in the collection.

If the amount of information to be returned cannot fit in the return buffer, then the SIGNAL_MORE_TO_DO bit is set in the retSignalFlags parameter, no error is returned, and the buffer is returned truncated on the last "whole" entry that fits into the buffer. There will never be a truncated entry in the returned buffer. Therefore, you should always call NIFReadEntries in a loop and test the SIGNAL_MORE_TO_DO bit in the SignalFlags parameter. This ensures that you obtain information about all the notes in a collection.

After each call to NIFReadEntries is completed, you must check that the returned buffer handle (8th argument) is not NULLHANDLE, and then call OSLockObject to lock the buffer and obtain the address of the requested data. Also check the number of entries returned (11th argument) to ensure that the buffer contains valid entries. When you are through using the buffer, you must call OSUnlockObject to unlock it and OSMemFree to deallocate it.

Note: Even though the number of entries returned and/or the returned buffer length are 0, you must use OSMemFree if the returned buffer handle is not NULLHANDLE. The return of a buffer handle that is not NULLHANDLE does not necessarily mean that entries were found by NIFReadEntries. Use the returned number of entries to determine whether the buffer contains valid entries.

Parameters :

Sample Usage :

/* This code fragment shows a typical call to NIFReadEntries. */

/* Set up the data structure, COLLECTIONPOSITION, that           */
/* controls where in the collection we will begin when we read  */
/* the collection.  Specify that we want to start at the beginning. */

CollPosition.Level = 0;
CollPosition.Tumbler[0] = 0;

/* Get a buffer of all the note IDs for the notes in this collection.
Check the return code to see if the collection is empty. */

do
{
error = NIFReadEntries(
   hCollection,    /* handle to this collection */
   &CollPosition,    /* where to start in collection */
   NAVIGATE_NEXT,   /* order to skip entries */
   1L,   /* number to skip */
   NAVIGATE_NEXT,   /* order to use after skipping */
   0xFFFF,    /* max return number */
   READ_MASK_NOTEID,    /* info we want */
   &hBuffer,    /* handle to info (return) */
   NULL,    /* length of buffer (return) */
   NULL,    /* entries skipped (return) */
   &NotesFound,    /* number of notes (return) */
   &SignalFlags);    /* share warning (return) */

if (error) return(error);

/* Lock down (freeze the location) of the buffer of notes IDs. Cast
the resulting pointer to the type we need. */

if (hBuffer != NULLHANDLE)
  {
  IdList = (NOTEID far *)OSLockObject(hBuffer);

/* Print out the list of all the note IDs in this collection. */

  for (i=0; i<NotesFound; i++)
   printf ("Note ID number %lu is: %lu\n", ++NumNotes,
                  IdList[i]);

/* Unlock the list of note IDs. */

  OSUnlockObject(hBuffer);

/* Free the memory allocated by NIFReadEntries. */

 OSMemFree(hBuffer);
 }

/* repeat loop if more signal flag is set */

} while (SignalFlags & SIGNAL_MORE_TO_DO);      


See Also :

NIFCloseCollection
----------------------------------------------------------------------------------------------------------