home *** CD-ROM | disk | FTP | other *** search
/ Zodiac Super OZ / MEDIADEPOT.ISO / FILES / 16 / FREEDOS.ZIP / FD_A4PRE.ZIP / SOURCE / MC-SWAP.ZIP / SWAPTEST.C < prev   
C/C++ Source or Header  |  1995-06-23  |  3KB  |  81 lines

  1. #include <stdio.h>
  2. #include "swap.h"
  3.  
  4. /*
  5.  *    This program is an example of how to use swap() to swap out the
  6.  *    current program, execute another in its place, then restore the
  7.  *    original program.  It should work with DDS MICRO-C PC86 v. 3.13.
  8.  *
  9.  */
  10.  
  11. int swap_return;
  12. unsigned char exec_return;
  13. unsigned char comspec[128];
  14. unsigned int dos_ptr;
  15.  
  16. main ()
  17.    {
  18.    printf ("Hello--we are now in SWAPTEST.  We are about to execute a DOS shell.\n\n");
  19.  
  20.    if (!xms_installed())
  21.       printf ("No ");
  22.    printf ("XMS driver detected.\n");
  23.  
  24.    if (!ems4_installed())
  25.       printf ("No ");
  26.    printf ("EMS 4.0 driver detected.\n");
  27.  
  28.  
  29. /*
  30.  * Now allocate another DOS block for this program, to demonstrate
  31.  *  new capability of SWAP 3.00 to swap all DOS blocks owned by a program
  32.  *
  33.  * Use _dos_allocmem() for Microsoft C 5.10 and 6.00,
  34.  * use allocmem() for Turbo C++ 1.0 and Turbo C 2.0.
  35.  * Both functions use same parameters.
  36.  * SWAP.ASM must be assembled WITHOUT /DNoFrag for this to work.
  37.  * Allocate a DOS block of 1024 paragraphs (16K bytes).
  38.  */
  39.    if((dos_ptr=alloc_seg (1024))==0)printf("Can't allocate far segment!\n");
  40.  
  41.    printf ("\n** Type EXIT to return to SWAPTEST **\n");
  42.  
  43.    if(!getenv ("COMSPEC",comspec))printf("Can't find COMSPEC variable!\n");
  44.  
  45.    swap_return = swap (comspec, "", &exec_return, "swaptest.fil");
  46.  
  47.    printf ("\n\nBack in SWAPTEST now.\n\n");
  48.  
  49.    switch (swap_return)
  50.       {
  51.       case SWAP_OK:        printf ("Successful, executed program returned %d.\n", (int)exec_return);
  52.                            break;
  53.  
  54.       case SWAP_NO_SHRINK: printf ("Unable to shrink DOS memory block.\n");
  55.                            break;
  56.  
  57.       case SWAP_NO_SAVE:   printf ("Unable to save program to memory or disk.\n");
  58.                            break;
  59.  
  60.       case SWAP_NO_EXEC:   printf ("DOS EXEC call failed.  Error is %d: ", (int)exec_return);
  61.                            switch (exec_return)
  62.                               {
  63.                               case BAD_FUNC:       printf ("Bad function.\n");                        break;
  64.                               case FILE_NOT_FOUND: printf ("Program file not found.\n");              break;
  65.                               case ACCESS_DENIED:  printf ("Access to program file denied.\n");       break;
  66.                               case NO_MEMORY:      printf ("Insufficient memory to run program.\n");  break;
  67.                               case BAD_ENVIRON:    printf ("Bad environment.\n");                     break;
  68.                               case BAD_FORMAT:     printf ("Bad format.\n");                          break;
  69.                               default:             printf ("Unexpected error code #%d (decimal).\n", (int)exec_return);
  70.                                                    printf ("Consult DOS technical reference manual.\n");
  71.                                                    break;
  72.  
  73.                               }
  74.       }
  75.  
  76.    if(dos_ptr)if((free_seg(dos_ptr))!=0)printf("Can't free far segment!\n");
  77.    return (0);
  78.  
  79.    }
  80.  
  81.