Description
Enumerates all of the jobs associated with a given queue or server.
Syntax
DWORD BatchEnumerateJobs (LPCTSTR queue, DWORD level, LPBYTE jobbuf, DWORD cbsize, LPDWORD cbneeded, LPDWORD jobcount);
Parameters
LPCTSTR queue |
Specifies the queue name. |
DWORD level |
Specifies the amount to information to be returned for each job. Levels 1 and 2 are supported, which correspond to the BATCH_JOB_INFO_1 andBATCH_JOB_INFO_2 structures, respectively. |
LPBYTE jobbuf |
Defines the buffer space to store an array of BATCH_JOB_INFO structures. |
DWORD cbsize |
Specifies the size of the buffer in bytes. |
LPDWORD cbneeded |
Specifies the size of the returned information. If cbsize is too small, ERROR_INSUFFICIENT_BUFFER is returned, and cbneeded is set to the needed size. |
LPDWORD jobcount |
Defines a pointer to contain the number of jobs returned in the jobbuf. |
Return Values
BATCH_ERROR_NO_SUCH_QUEUE |
Could not find the named queue. |
ERROR_INVALID_LEVEL |
The level parameter is not 1 or 2. |
BATCH_ERROR_BAD_QUEUE_NAME |
The queue name syntax is not valid. |
Example Program
#include <iostream.h>
#include "batchapi.h"
#define MAX_LENGTH 25
void main()
{
LPBYTE Jobid;
LPCTSTR QueName=NULL;
char * pTemp=NULL;
DWORD ReturnVal;
DWORD Jobcount;
DWORD Level;
DWORD Need;
DWORD CbSize;
cout << endl << "STARTING THE EXECUTION OF BATCHENUMERATEJOBS API "<< endl;
CbSize = BATCH_JOB_ID_SIZE + 4;
pTemp = new char [MAX_LENGTH];
if (pTemp ==NULL){
cout << "Unable to allocate the memory. Exiting." << endl;
exit(0);
}
cout << " Enter the Queue to Enumerate the Jobs ";
cin >> pTemp;
QueName = (const char *) pTemp;
cout << " Enter the Level with Which to Enumerate the Jobs ";
cin >> Level;
ReturnVal = BatchEnumerateJobs(QueName , Level , NULL,0,&Need,&Jobcount);
// first time to get the cbsize ( which is returned in 5th(Need) argument)
Jobid = (LPBYTE)LocalAlloc(0,Need);
if (Jobid ==NULL){
cout << "unable to allocate the memory.\n Exiting"<<endl;
delete [] pTemp;
exit(0);
}
CbSize= Need;
ReturnVal = BatchEnumerateJobs(QueName , Level , Jobid,CbSize,&Need,&Jobcount);
// Now we have the Data about the jobs from the queue QueName in Jobid which can
// be retrieved using an BATCH_JOB_INFO_2 or a BATCH_JOB_INFO_1 pointer variable
// For further Info See BatchSetJobInfo API example.
switch(ReturnVal)
{
case BATCH_ERROR_NO_SUCH_QUEUE :
cout << " Could not find the named queue. : " << QueName << endl;
break;
case ERROR_INVALID_LEVEL :
cout << " The level parameter is not 1 or 2. " << endl;
break;
case BATCH_ERROR_BAD_QUEUE_NAME :
cout << " The queue name syntax is not valid. : " << QueName << endl;
break;
default :
cout << "Successfully enumerated the jobs " << endl;
}
cout << endl << "FINISHED THE EXECUTION OF BATCHENUMERATEJOBS API "<< endl;
delete [] pTemp;
LocalFree(Jobid);
}