#include <windows.h> // Windows APIs and datatypes #include <stdlib.h> // For atoi #include "cwbsoapi.h" // System Object Access APIs int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow) { CWBSO_LIST_HANDLE hList = CWBSO_NULL_HANDLE; // List handle CWBSO_ERR_HANDLE hError = CWBSO_NULL_HANDLE; // Error handle CWBSO_PARMOBJ_HANDLE hParmObject = CWBSO_NULL_HANDLE; // Parm object CWBSO_OBJ_HANDLE hObject = CWBSO_NULL_HANDLE; // Object handle unsigned int rc, setRC; // System Object Access return codes unsigned long bytesNeeded = 0; // Bytes needed unsigned short errorIndex = 0; // Error index (SetObjAttr) char szString[100]; // Buffer for formatting int totalPages = 0; // Total pages int i = 0; // Loop counter int nNbrChanged = 0; // Count of changed objects MessageBox(GetFocus(), "Start of Processing", "PRIORITY", MB_OK); //******************************************************************** // Create a list of spooled files. Set desired filter criteria. //******************************************************************** // Create a list of spooled files on system SYSNAME CWBSO_CreateListHandle("SYSNAME", "APPNAME", CWBSO_LIST_SFL, &hList); // Only include spooled files for device P3812 CWBSO_SetListFilter(hList, CWBSO_SFLF_DeviceFilter, "P3812"); //******************************************************************* // Open the list. //******************************************************************* // Create an error handle CWBSO_CreateErrorHandle(&hError); // Open the list of spooled files rc = CWBSO_OpenList(hList, hError); // If an error occurred, display a message box if (rc == CWBSO_ERROR_OCCURRED) CWBSO_DisplayErrMsg(hError); else { //***************************************************************** // Set up to change output priority for all objects in the list. //***************************************************************** // Create a parameter object to hold the attribute changes CWBSO_CreateParmObjHandle(&hParmObject); // Set the parameter to change the output priority to '9' CWBSO_SetParameter(hParmObject, CWBSO_SFL_OutputPriority, "9", hError); //****************************************************************** // Loop through the list, changing the output priority for any // files that have more than 10 total pages. Loop will // terminate when CWBSO_WaitForObj // returns CWBSO_BAD_LIST_POSITION, indicating that there // are no more objects in the list. //****************************************************************** // Wait for first object in the list rc = CWBSO_WaitForObj(hList, i, hError); // Loop through entire list while (rc == CWBSO_NO_ERROR) { // Get the list object at index i CWBSO_GetObjHandle(hList, i, &hObject, hError); // Get the total pages attribute for this spooled file CWBSO_GetObjAttr(hObject, CWBSO_SFL_TotalPages, szString, sizeof(szString), &bytesNeeded,; hError); totalPages = atoi(szString); // Update the output priority if necessary if (totalPages > 10) { // Change the spool file's output priority to '9' setRC = CWBSO_SetObjAttr(hObject, hParmObject, &errorIndex, hError); if (setRC == CWBSO_NO_ERROR) nNbrChanged++; } // Delete the object handle CWBSO_DeleteObjHandle(hObject); // Increment list item counter i++; // Wait for next list object rc = CWBSO_WaitForObj(hList, i, hError); } /* end while */ // Parameter object no longer needed CWBSO_DeleteParmObjHandle(hParmObject); } /* end if */ // Display the number of spooled files that had priority changed wsprintf (szString, "Number of spool files changed: %d", nNbrChanged); MessageBox(GetFocus(), szString, "PRIORITY", MB_OK); //******************************************************************** // Processing complete - clean up and exit. //******************************************************************** // Close the list CWBSO_CloseList(hList,hError); // Clean up handles CWBSO_DeleteErrorHandle(hError); CWBSO_DeleteListHandle(hList); //******************************************************************** // Return from WinMain. //******************************************************************** return 0; }