This example determines the number of items in the Task List, allocates memory for the required buffer, and then calls WinQuerySwitchList again to fill the buffer with the information about each item in the Task List.

#define INCL_DOSMEMMGR
#define INCL_DOSERRORS
#define INCL_WINSWITCHLIST  /* Or INCL_WIN, INCL_PM */
#include <OS2.H>

#define MEMPOOL  40000   /* Size of local memory pool area */

HAB      hab        = NULLHANDLE;
HWND     hwndFrame  = NULLHANDLE;
ULONG    cbItems    = 0,            /* Number of items in list */
         ulBufSize  = 0;            /* Size of buffer for information */
PVOID    pvBase     = NULL;         /* Pointer to local memory pool */
PSWBLOCK pswblk     = NULL;         /* Pointer to information returned */
APIRET   rc         = NO_ERROR;     /* Return code from Dos APIs */

     /* Allocate a large block of memory (uncommitted) and make
        it available for suballocation.  This allows the system
        to commit memory only when it is actually needed.       */

rc = DosAllocMem( &pvBase, MEMPOOL, PAG_READ | PAG_WRITE );
rc = DosSubSetMem( pvBase, DOSSUB_INIT | DOSSUB_SPARSE_OBJ, MEMPOOL );

     /* Determine the number of items in the list and calculate
        the size of the buffer needed.                          */

cbItems = WinQuerySwitchList(hab, NULL, 0);
ulBufSize = (cbItems * sizeof(SWENTRY)) + sizeof(HSWITCH);

     /* Allocate the buffer from our memory pool */

rc = DosSubAllocMem( pvBase, (PVOID) &pswblk, ulBufSize);

   /* Call WinQuerySwitchList again to fill our buffer with information */

cbItems = WinQuerySwitchList(hab, pswblk, ulBufSize);


[Back] [Next]