The following example shows a typical calling sequence for retrieving a list of spooled files.
/********************************************************/
/* List all spooled files for the current user and */
/* display them to the user. */
/********************************************************/
#ifdef UNICODE
#define _UNICODE
#endif
#include <windows.h>
#include <stdio.h>
#include "CWBOBJ.H"
main(int argc, char *argv[ ], char *envp[ ])
{
cwbOBJ_ListHandle listHandle;
cwbOBJ_ObjHandle splFHandle;
unsigned int ulRC;
unsigned long ulListSize, ulObjPosition, ulBytesNeeded;
cwbOBJ_KeyID keysWanted[] = { CWBOBJ_KEY_SPOOLFILE,
CWBOBJ_KEY_USER };
unsigned long ulNumKeysWanted = sizeof(keysWanted)/sizeof(*keysWanted);
char szSplFName[11];
char szUser[11];
ulRC = cwbOBJ_CreateListHandle(_TEXT("ANYAS400"),
CWBOBJ_LIST_SPLF,
&listHandle,
0);
if (ulRC == CWB_OK)
{
/* Set up the filter for the list to be opened with */
/* NOTE: this is just for example, the user defaults */
/* to *CURRENT, so this isn't really needed. */
cwbOBJ_SetListFilter(listHandle, CWBOBJ_KEY_USER,
_TEXT("*CURRENT"), 0);
/* Optionally call to cwbOBJ_SetListAttrsToRetrieve to*/
/* make walking the list faster */
ulRC = cwbOBJ_SetListAttrsToRetrieve(listHandle,
ulNumKeysWanted,
keysWanted,
0);
/* open the list - this will build the list of spooled*/
/* files. */
ulRC = cwbOBJ_OpenList(listHandle,
CWBOBJ_LIST_OPEN_SYNCH,
0);
if (ulRC == CWB_OK)
{
/* Get the number of items that are in the list */
ulRC = cwbOBJ_GetListSize(listHandle,
&ulListSize,
(cwbOBJ_List_Status *)0,
0);
if (ulRC == CWB_OK)
{
/* walk through the list of items, displaying */
/* each item to the user */
ulObjPosition = 0;
while (ulObjPosition < ulListSize)
{
/*******************************************/
/* Get a handle to the next spooled file in*/
/* the list. This handle is valid while */
/* the list is open. If you want to */
/* maintain a handle to the spooled file */
/* after the list is closed, you could call*/
/* cwbOBJ_CopyObjHandle() after this call. */
/*******************************************/
ulRC = cwbOBJ_GetObjHandle(listHandle,
ulObjPosition,
&splFHandle,
0);
if (ulRC == CWB_OK)
{
/****************************************/
/* call cwbOBJ_GetObjAttr() to get info */
/* about this spooled file. May also */
/* call spooled file specific APIs */
/* with this handle, such as */
/* cwbOBJ_HoldSplF(). */
/****************************************/
ulRC = cwbOBJ_GetObjAttr(splFHandle,
CWBOBJ_KEY_SPOOLFILE,
(void *)szSplFName,
sizeof(szSplFName),
&ulBytesNeeded,
NULL,
0);
if (ulRC == CWB_OK)
{
ulRC = cwbOBJ_GetObjAttr(splFHandle,
CWBOBJ_KEY_USER,
(void *)szUser,
sizeof(szUser),
&ulBytesNeeded,
NULL,
0);
if (ulRC == CWB_OK)
{
printf("%3u: %11s %s\n",
ulObjPosition, szSplFName, szUser);
} else {
/* ERROR on GetObjAttr! */
}
} else {
/* ERROR on GetObjAttr! */
}
/* free this object handle */
cwbOBJ_DeleteObjHandle(splFHandle, 0);
} else {
/* ERROR on GetObjHandle! */
}
ulObjPosition++;
}
} else {
/* ERROR on GetListSize! */
}
cwbOBJ_CloseList(listHandle, 0);
} else {
/* ERROR on OpenList! */
}
cwbOBJ_DeleteListHandle(listHandle, 0);
}