home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c017 / 34.ddi / CSWAPXXX.ZIP / SWAPTEST.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-09-06  |  2.5 KB  |  70 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #include "swap.h"
  6.  
  7. /*
  8.  *    This program is an example of how to use swap() to swap out the
  9.  *    current program, execute another in its place, then restore the
  10.  *    original program.  It should work with Turbo C (all versions),
  11.  *    Turbo C++ 1.0, and Microsoft C 5.10.
  12.  *
  13.  */
  14.  
  15. int swap_return;
  16. unsigned char exec_return;
  17. char *comspec;
  18.  
  19. main (int argc, char *argv[])
  20.    {
  21.  
  22.    printf ("Hello--we are now in SWAPTEST.  We are about to execute a DOS shell.\n\n");
  23.  
  24.    if (!xms_installed())
  25.       printf ("No ");
  26.    printf ("XMS driver detected.\n");
  27.  
  28.    if (!ems_installed())
  29.       printf ("No ");
  30.    printf ("EMS driver detected.\n");
  31.  
  32.  
  33.    printf ("\n** Type EXIT to return to SWAPTEST **\n\n");
  34.  
  35.    comspec = getenv ("COMSPEC");
  36.    swap_return = swap (comspec, "", &exec_return, "swap.fil");
  37.  
  38.    printf ("\n\nBack in SWAPTEST now.\n\n");
  39.  
  40.    switch (swap_return)
  41.       {
  42.       case SWAP_OK:        printf ("Successful, executed program returned %d.\n", (int)exec_return);
  43.                            break;
  44.  
  45.       case SWAP_NO_SHRINK: printf ("Unable to shrink DOS memory block.\n");
  46.                            break;
  47.  
  48.       case SWAP_NO_SAVE:   printf ("Unable to save program to memory or disk.\n");
  49.                            break;
  50.  
  51.       case SWAP_NO_EXEC:   printf ("DOS EXEC call failed.  Error is %d: ", (int)exec_return);
  52.                            switch (exec_return)
  53.                               {
  54.                               case BAD_FUNC:       printf ("Bad function.\n");                        break;
  55.                               case FILE_NOT_FOUND: printf ("Program file not found.\n");              break;
  56.                               case ACCESS_DENIED:  printf ("Access to program file denied.\n");       break;
  57.                               case NO_MEMORY:      printf ("Insufficient memory to run program.\n");  break;
  58.                               case BAD_ENVIRON:    printf ("Bad environment.\n");                     break;
  59.                               case BAD_FORMAT:     printf ("Bad format.\n");                          break;
  60.                               default:             printf ("Unexpected error code.\n");
  61.                                                    printf ("Consult DOS technical reference manual.\n");
  62.                                                    break;
  63.  
  64.                               }
  65.       }
  66.  
  67.    return (0);
  68.    }
  69.  
  70.