This example finds all occurrences of an object type in a folder.

 VOID  clsFindEverybody(SOMAny *self)
{
   BOOL      rc;                 /* Return from methods */
   HFIND     hFind       = 0;    /* Handle for repeated finds */
   CLASS     Class[2];           /* List of classes to look for */
   OBJECT    Object[10];         /* Objects returned from search */
   ULONG     ulCount     = 10;   /* Count of objects to find / or found */
   WPFolder  *folder     = 0;    /* Pointer to folder for search */
   ULONG     errorid     = 0;    /* Error returned from previous search */
   CHAR      sz[CCHMAXPATH];     /* Title string to look for */
   PSZ       title = sz;

   Class[0] = _WPFolder;
   Class[1] = NULL;
   /* Get the pointer to the desktop (since that is where we are looking) */

   folder = _wpclsQueryFolder( _WPFolder, "<WP_DESKTOP>", TRUE );

   _wpclsSetError( _WPObject, 0 );      /* Reset the error indicators */
   rc = 0;

         /* Attempt to find the first 10 objects matching our criteria */

   ulCount = 10;
   rc =_wpclsFindObjectFirst(_WPObject,     /* Class self pointer */
                             Class,         /* Pointer to array of class objects */
                             &hFind,        /* Handle for wpclsFindObjectNext */
                             NULL,          /* Find EVERYTHING */
                             folder,        /* Pointer to folder of interest */
                             TRUE,          /* Search all folders in tree */
                             NULL,          /* No extended criteria */
                             Object,        /* Array of object pointers */
                             &ulCount );    /* Number requested and number found */

   errorid = _wpclsQueryError( _WPObject);  /* Get errorid (may still be OK) */

   if ((!rc && (errorid == WPERR_BUFFER_OVERFLOW)) || rc) {

              /***** Process objects found here ******/

   } else {
      somPrintf(" _wpclsFindObjectFirst failed, errorid=%u\n", errorid );
      return;
   } /* endif */

   do {

      _wpclsSetError( _WPObject, 0 );    /* Reset error indicators */
      rc = 0;

             /* Look for next 10 objects */

      rc =_wpclsFindObjectNext(_WPObject,       /* Self */
                                hFind,          /* Handle from previous Find */
                                Object,         /* Objects found */
                                &ulCount );     /* Number to look for. On
                                                   return, number found */

      errorid = _wpclsQueryError( _WPObject );

      if ((!rc && (errorid == WPERR_BUFFER_OVERFLOW)) || rc) {

              /***** Process objects found here ******/

      } else {
            somPrintf("_wpclsFindObjectNext failed, errorid=%u\n", errorid);
            return;
      } /* endif */

   } while ( errorid == WPERR_BUFFER_OVERFLOW ); /* enddo */

   _wpclsSetError( _WPObject, 0 );    /* Reset error indicators */
   rc = 0;

               /* Indicate find complete */

   rc =_wpclsFindObjectEnd( _WPObject, hFind );

   if (!rc) {
     errorid = _wpclsQueryError( _WPObject );
     somPrintf( "_wpclsFindObjectEnd failed, errorid=%u\n", errorid );
     return;
   }

   return;
}


[Back] [Next]