home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / PGMUTL / SWITCH22.ZIP / SWITCH.DOC < prev    next >
Encoding:
Text File  |  1989-02-04  |  40.0 KB  |  1,387 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.                                        Switch!
  34.                 Copyright (C)1988, Curtis Little  All Rights Reserved
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.                    For IBM PCs XTs ATs and PS2s or 100% Compatibles
  59.                                  Supports EMS (3.0+)
  60.  
  61.  
  62.           Clipper is a trademark of the Nantucket Corp
  63.           DesqView is a trademark of QuarterDeck
  64.           MS-DOS/QuickBASIC/MS BASIC are trademarks of Microsoft
  65.           IBM BASIC is a trademark of International Business Machines
  66.           Turbo C/TLINK/Turbo Pascal are trademarks of Borland Intl.
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.                                       Chapter 1
  80.  
  81.                                     Introduction
  82.  
  83.  
  84.           1.1  What you should read
  85.  
  86.  
  87.           A lot of information about Switch! is in this manual.  If you
  88.           don't want to read everything you should AT LEAST read the entire
  89.           chapter titled 'Using Switch!'.  When you read the chapter 'Using
  90.           Switch!' pay close attention to the different function names for
  91.           the various languages supported by Switch! along with the
  92.           instructions for linking Switch! into your applications.  You
  93.           should also read the license because by using Switch! you are
  94.           bound by the terms in the license agreement.  I personally
  95.           recommend that you read the entire manual, but if you don't at
  96.           least read the chapter about using Switch! you're probably going
  97.           to have problems linking it to your application.
  98.  
  99.  
  100.           1.2  Ok, Back to the Introduction
  101.  
  102.  
  103.           How many times have you wanted to shell out of one program and
  104.           execute another only to find there isn't enough memory left?  If
  105.           only both programs could fit in memory together long enough to
  106.           get the job done... Introducing Switch!.  Switch! is a function
  107.           written in 100% assembly (although Switch! itself is entirely
  108.           assembly the Clipper version uses C to interface Clipper with
  109.           Switch!) that allows a large application to load and run another
  110.           program whose memory requirements are larger than the first
  111.           application leaves free.  Switch! swaps your application to disk
  112.           or EMS to free memory to load and execute another program.  If
  113.           Switch! had been used in all commercial programs a DOS shell
  114.           would not be missing from any of them and there would be more
  115.           than enough memory to load another large application.
  116.  
  117.  
  118.           1.3  Program Requirements
  119.  
  120.  
  121.           Switch! will work properly with most system setups.  The main
  122.           requirement is that DOS 2.0 or above is needed for proper
  123.           operation.  The other requirement is that a disk must be
  124.           available that has enough space to save the switched application
  125.           (or registered versions can use EMS 3.0+ instead).
  126.  
  127.  
  128.  
  129.  
  130.                                         - 2 -
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.           1.4  Languages Supported
  140.  
  141.  
  142.           Switch! supports QuickBASIC, MS BASIC, IBM BASIC, C, Assembly,
  143.           Turbo Pascal and Clipper applications.  There are several OBJ
  144.           files included that support the different languages as follows:
  145.  
  146.               o  SWITCH.OBJ   - Switch! for C and Assembly.
  147.  
  148.               o  SWITCH87.OBJ - Switch! for Clipper Summer '87.
  149.  
  150.               o  SWITCHQB.OBJ - Switch! for BASIC programs.
  151.  
  152.               o  SWITCHTP.OBJ - Switch! for Turbo Pascal.
  153.  
  154.           Be sure to link in the right object file for the language you're
  155.           using or Switch! will not work properly!
  156.  
  157.  
  158.           1.5  Models Supported
  159.  
  160.  
  161.           The assembly code for Switch! was designed to support all of the
  162.           standard memory models, but the shareware version only supports
  163.           the LARGE model (unless the language being supported REQUIRES a
  164.           different memory model i.e. the shareware QuickBASIC version of
  165.           Switch! is in the medium model as required by QB).  To get
  166.           Switch! working with another model you either need to prototype
  167.           it as far or register to get the source code.
  168.  
  169.           The models supported by the shareware version of Switch! are:
  170.  
  171.                Language                 Shareware Model
  172.                --------                 ---------------
  173.                C/Assembly Switch!  -    LARGE model.
  174.                QB, MS B, IBM B     -    MEDIUM model.
  175.                Clipper             -    LARGE model.
  176.                Turbo Pascal        -    LARGE model.
  177.  
  178.           (Registered users can assemble Switch! to any desired memory
  179.           model providing you have MASM 5.0 or above).
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.                                         - 3 -
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211.                                       Chapter 2
  212.  
  213.                                  Registering Switch!
  214.  
  215.  
  216.           Shareware is software that can be freely copied and shared with
  217.           others.  Although the software may be freely distributed in
  218.           UNMODIFIED form it is still copyrighted software which the author
  219.           supports.
  220.  
  221.           Shareware provides you a way to test software before spending
  222.           your money.  This helps you get more for your dollar by allowing
  223.           you to test the software before paying.
  224.  
  225.           The cost of registering Switch! is $20.00.  The registration form
  226.           is in the file called SWITCH.REG.
  227.  
  228.  
  229.           2.1  Registration Benefits
  230.  
  231.  
  232.           Registering Switch! provides the following benefits:
  233.  
  234.               o  You will receive a disk containing the assembly source
  235.                  code for Switch!.  (MASM 5.0 or above required to assemble
  236.                  the source).  The source module can be assembled to
  237.                  support ANY of the languages Switch! works with.
  238.  
  239.               o  No royalty fees!!
  240.  
  241.               o  Once you've registered Switch! you are free to use it in
  242.                  any future executable applications you develop.
  243.  
  244.               o  Bulletin Board Support.
  245.  
  246.           2.1.1  Registration for Businesses
  247.  
  248.           My registration policy is pretty lax.  If a business registers
  249.           Switch! the business may use Switch! freely WITHIN the business
  250.           (I don't want a registration for each machine or each person
  251.           working in the business - the one $20.00 registration for the
  252.           business is enough).  If Switch! is used in commercial
  253.           applications (by commercial I mean those programs distributed
  254.           commercially.  I'm not talking about a consultant developing a
  255.           system for a client.) I do ask that I be given credit in the
  256.           program documentation for developing the Switch! part.
  257.  
  258.  
  259.  
  260.  
  261.  
  262.                                         - 4 -
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277.                                       Chapter 3
  278.  
  279.                                        License
  280.  
  281.  
  282.           I am offering you a license to use Switch! on a TRIAL BASIS.
  283.           Unregistered versions may be used to write programs which will
  284.           only be used by yourself.  Distribution of programs developed
  285.           with an UNREGISTERED version of Switch! is a direct violation of
  286.           this license agreement.
  287.  
  288.           Registered versions of Switch! may be used by the REGISTERED
  289.           OWNER to develop programs that may be given away or sold without
  290.           additional license or fees.
  291.  
  292.           The source code for Switch! is provided to registered users to
  293.           allow development of specialized functions that suit your needs.
  294.           As a registered owner you have the right to edit or modify the
  295.           source code for YOUR OWN USE, but you may not give it away or
  296.           sell it in source or object form (this includes object
  297.           libraries).  You may incorporate the code into your EXECUTABLE
  298.           programs (which may be given away or sold), as long as your
  299.           programs do not compete (directly or indirectly) with Switch!.
  300.           Distribution of Switch! or a derivative of Switch! in object or
  301.           object library format requires prior written consent from the
  302.           author (a special license/price agreement can be made to allow
  303.           you to distribute Switch! in object/object library format.
  304.           Please write if you're interested in this special license).
  305.  
  306.           Businesses, government institutions, and other commercial users
  307.           of Switch! MUST register.
  308.  
  309.           If Switch! is used in a commercial application the documentation
  310.           must give the author (Curtis Little) credit for the development
  311.           of Switch!.
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.                                         - 5 -
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338.  
  339.  
  340.  
  341.  
  342.  
  343.                                       Chapter 4
  344.  
  345.                                       Warranty
  346.  
  347.  
  348.           With respect to the physical diskette sent to registered owners,
  349.           the author warrants the same to be free from defects in materials
  350.           and workmanship for a period of 60 days from the date of
  351.           registration.  In the event of notification within the warranty
  352.           period of defects in material or workmanship the author will
  353.           replace the defective diskette.  The remedy for breach of this
  354.           warranty shall be limited to replacement and shall not encompass
  355.           any other damages, including but not limited to loss of profit,
  356.           and special, incidental, consequential, or other similar claims.
  357.  
  358.           The author specifically disclaims all other warranties, expressed
  359.           or implied, including but not limited to implied warranties of
  360.           merchantability and fitness for a particular purpose and the
  361.           program license granted herein in particular, and without
  362.           limiting operation of the program license with respect to any
  363.           particular application, use, or purpose.  In no event shall the
  364.           author be liable for any loss of profit or any other commercial
  365.           damage resulting from the use (or inability to use) Switch!, even
  366.           if the author has been advised ahead of time that the possibility
  367.           for damage exists.
  368.  
  369.  
  370.  
  371.  
  372.  
  373.  
  374.  
  375.  
  376.  
  377.  
  378.  
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.                                         - 6 -
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.  
  404.  
  405.  
  406.  
  407.  
  408.  
  409.                                       Chapter 5
  410.  
  411.                                     Using Switch!
  412.  
  413.  
  414.           This chapter covers how to use Switch!.  Before getting into the
  415.           details of using it I'll briefly introduce you to what Switch!
  416.           does for your applications.  Afterwards the details for calling
  417.           Switch! will be covered followed by an explanation of how to link
  418.           Switch! in with your programs.
  419.  
  420.  
  421.           5.1  How It Works
  422.  
  423.  
  424.           Switch! works by performing a little "magic" with the way DOS
  425.           manages memory.  When called it attempts to free up the amount of
  426.           memory the program requires (or all possible if it can't save as
  427.           much as specified) to disk or EMS.
  428.  
  429.           Switch! reduces the resident portion of a program while another
  430.           is executed by temporarily storing the "parent" program to disk
  431.           or EMS.  After the "child" program is finished the "parent" is
  432.           read back in memory by Switch! and execution resumes where it
  433.           left off (resumes at the point after Switch! was called).
  434.  
  435.           Let's look at an example of how memory looks before you call
  436.           Switch! vs how it looks right before Switch! is ready to load the
  437.           second program.
  438.  
  439.              Before Calling Switch!          After Calling Switch!
  440.                                              (before 2nd program is loaded)
  441.                 +--------------+             +--------------+
  442.                 |              |             |              |
  443.                 | Free memory  |             |              |
  444.                 +--------------+             |              |
  445.                 |Application 1 |             |              |
  446.                 | (Block 2)    |             |              |
  447.                 |--------------|             |              |
  448.                 | Free         |             |              |
  449.                 |--------------|             |              |
  450.                 | Application 1|             | Free memory  |
  451.                 |              |             +--------------+
  452.                 |(First Block) |             | Application 1|
  453.                 +--------------+             +--------------+
  454.                 | DOS Area     |             | DOS Area     |
  455.                 |              |             |              |
  456.                 +--------------+             +--------------+
  457.  
  458.  
  459.  
  460.                                         - 7 -
  461.  
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468.  
  469.           The example above graphically illustrates what Switch! does.  As
  470.           can be seen by the example a lot of memory is cleared by Switch!
  471.           making it available to the program to be loaded.  (Switch! can be
  472.           called over and over from one application to another without
  473.           problems!) - To see this execute the demo program and keep
  474.           telling it to run itself.
  475.  
  476.  
  477.           5.2  Using Switch!
  478.  
  479.  
  480.           The prototype for Switch! is as follows:
  481.  
  482.           (For examples of calling Switch! look in the Appendix at the back
  483.           of this manual!).  You will notice that the function names for
  484.           the various languages are DIFFERENT!  Please call the right one
  485.           for the language you are using.
  486.  
  487.           ** For the QuickBASIC/MS BASIC/IBM BASIC Version **
  488.           SWITCH( drive%, memrequired%, command_line$, ret_val% )
  489.  
  490.           ** For the C/Assembly Version **
  491.           int switch_( int drive, int memrequired, char *command_line );
  492.  
  493.           ** For the Clipper Version **
  494.           SWITCH87( [drive] [,memrequired] [,command_line] )
  495.  
  496.           ** For the Turbo Pascal Version **
  497.           SWITCH( drive, memrequired : integer; command_line : string80 ) :
  498.                integer;
  499.  
  500.           The parameters and meanings are:
  501.  
  502.             drive - This parameter specifies the disk drive to store the
  503.             temporary file on.  A value of 0 specifies to save the file on
  504.             the drive that is current when Switch! is called.  A value of 1
  505.             specifies the A: drive, 2 the B: drive etc...
  506.  
  507.             NOTES:  The drive parameter is optional for Clipper (all
  508.             parameters are optional for the Clipper version of Switch!).
  509.             If this parameter isn't specified it is assumed to be zero.
  510.  
  511.             With the registered version EMS will automatically be used
  512.             instead of a disk file when possible.
  513.  
  514.             memrequired - This parameter specifies the amount of K memory
  515.             required by the program to run.  If the value you specify is
  516.             more than can be saved Switch! will save as much memory as
  517.             possible.  A value of zero also causes Switch! to save all
  518.             memory possible.
  519.  
  520.             NOTES:  This parameter is optional when using the Clipper
  521.             version.  If you don't specify the amount of memory required a
  522.             default of zero is assumed.
  523.  
  524.  
  525.  
  526.                                         - 8 -
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534.  
  535.             Switch! frees memory in an intelligent manner.  Switch! first
  536.             checks to see if the specified amount of memory is free.  If
  537.             the memory isn't already free Switch! will only free enough
  538.             memory to reach the amount specified.  For instance, if you
  539.             specify 64K and there is already 60K free memory Switch! will
  540.             only free 4K to reach the amount specified.
  541.  
  542.             command_line - This parameter specifies the command line to
  543.             execute after memory is saved.  For instance, a typical command
  544.             line might look like:
  545.                DIR /W /P
  546.             or
  547.                TC temp.c
  548.  
  549.             NOTES:  For the C/Assembly version of Switch! a NULL pointer
  550.             for the command line causes a DOS shell to be used.  I.E.  The
  551.             statement:  switch( 0, 0, NULL | "" ) (where either the NULL
  552.             pointer or pointer to a NULL character is passed) would cause
  553.             Switch! to save as much memory as possible and then execute a
  554.             DOS shell.  The command_line should be a MAXIMUM of 80
  555.             characters.  If the command_line parameter is longer than 80
  556.             characters the excess is ignored.
  557.  
  558.             The command_line parameter is optional with the Clipper version
  559.             of Switch!.  If the command_line isn't specified when calling
  560.             from Clipper the default DOS shell will be used.
  561.  
  562.             ret_val - This parameter is only used with the BASIC version of
  563.             Switch!.  This parameter is used to return the status back to
  564.             BASIC programs (the BASIC version of Switch! is a subprogram
  565.             instead of a function to make it compatible with QB 3.0).
  566.  
  567.             RETURN VALUE:  The value returned by Switch! indicates whether
  568.             or not an error occurred during the switch.  Please see the
  569.             list of error codes at the end of this document for a
  570.             description of the different values returned by Switch! along
  571.             with the suggested actions for each error.
  572.  
  573.           5.2.1  CLIPPER NOTES
  574.  
  575.           Since all parameters are optional with Clipper you should be
  576.           aware of how the parameters you do pass are interpreted by
  577.           Switch87!.  The first numeric parameter encountered is assumed to
  578.           be the drive.  The first character parameter encountered is
  579.           assumed to be the command_line (parameters following the
  580.           command_line parameter are ignored by Switch87!).
  581.  
  582.           Currently this function only works with the Summer 87 version of
  583.           Clipper, but should be easy for you to interface with the
  584.           Autumn 86 version of Clipper.
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.  
  592.                                         - 9 -
  593.  
  594.  
  595.  
  596.  
  597.  
  598.  
  599.  
  600.  
  601.           5.3  Linking Switch! in Your Applications
  602.  
  603.  
  604.           Switch! is distributed as an object file.  The object file can be
  605.           linked to applications you develop allowing Switch! to be called
  606.           as a function.  As mentioned several times throughout this
  607.           document there are several versions of Switch!.  The first
  608.           version that is intended for use in programs written in C,
  609.           assembly etc.. is called SWITCH.OBJ.  The second version for
  610.           Clipper Summer '87 is called SWITCH87.OBJ.  The last version for
  611.           use in BASIC programs is called SWITCHQB.OBJ.  To link the files
  612.           in with your application you simply include the proper module
  613.           name for the language you are using on the link line.  For
  614.           example to link SWITCH.OBJ to a C application the command line
  615.           might look like:
  616.                link SC.OBJ SWITCH.OBJ,,,C:\MISC\MYLIB.LIB
  617.                      ^          ^
  618.                      |          |
  619.                      |          This is the Switch! OBJ file for C/Assembly
  620.                      |
  621.                      This would be the first compiled C module for the
  622.                      program you are writing!
  623.  
  624.  
  625.           An example link for the Clipper version of Switch! might look
  626.           like:
  627.  
  628.               plink86 fi SC,SWITCH87 lib \clipper\clipper,\clipper\extend
  629.                          ^      ^
  630.                          |      |
  631.                          |      This is the Switch! OBJ file for Clipper
  632.                          |
  633.                          This is the first compiled Clipper module!
  634.  
  635.  
  636.           An example link for QuickBASIC would be:
  637.  
  638.                link SC.OBJ SWITCHQB.OBJ,,,BRUN30.LIB
  639.                      ^          ^
  640.                      |          |
  641.                      |          This is the Switch! OBJ file for BASIC.
  642.                      |
  643.                      This is the first compiled BASIC module!
  644.  
  645.  
  646.           Turbo Pascal doesn't use an external linker to link in OBJ files.
  647.           Instead you declare the function as a far EXTERNAL function and
  648.           use the $L directive to include the OBJ file.  Please refer to
  649.           the Turbo Pascal manual for details on how to include assembly
  650.           object modules.
  651.  
  652.  
  653.           Switch! is only able to free memory from the end of itself up.
  654.           This means that where you place Switch! in the link line will
  655.  
  656.  
  657.  
  658.                                        - 10 -
  659.  
  660.  
  661.  
  662.  
  663.  
  664.  
  665.  
  666.  
  667.           have a direct bearing on the maximum amount of memory Switch!
  668.           will be able to free.  For the best results you should write a
  669.           small program that contains a single line (calling the main
  670.           module of the program).  For example:  DO MAINMENU (in Clipper).
  671.           Then you could specify Switch! on the link line immediately after
  672.           the small program module.  I.E.
  673.  
  674.                PLINK86 fi TEST,SWITCH87,MAINMENU ...
  675.  
  676.           Creating a small program as explained above will make it possible
  677.           for Switch! to save as much memory as possible.  When linked in
  678.                                                                    1
  679.           like this Switch! can free all but around 7-8K of memory  (and
  680.           you Clipper programmers know how much of a cut that is!).  When
  681.           EMS is used the save/restore of a 640K application is almost
  682.           instant!
  683.  
  684.           Basically speaking the closer Switch! is to the start of the
  685.           program (i.e. linked in first) the more memory it can free when
  686.           called.  Note that any modules that have interrupt handlers
  687.           should be linked in the code BEFORE Switch! (See 'Tips for Using
  688.           Switch!').
  689.  
  690.  
  691.           5.4  Switch! on a Network
  692.  
  693.  
  694.           Using Switch! on a Network is not a problem.  It can access the
  695.           network drives without a hitch since DOS is used for the file
  696.           I/O.  In addition there isn't a problem with multiple saves to
  697.           the same drive because Switch! creates a temporary file (it never
  698.           overwrites an existing file - instead a unique name is
  699.           generated).  Note that my saying it creates a temporary file
  700.           doesn't mean that DOS 3.0 is required - it isn't because I wrote
  701.           my own function to calculate a temporary file name to make
  702.           Switch! work with older versions of DOS.
  703.  
  704.  
  705.           5.5  Should I Switch! to EMS or Disk?
  706.  
  707.  
  708.           Actually this isn't a question you have to worry about.  Non-
  709.           registered versions of Switch! will only switch to disk.
  710.           Registered versions automatically check for EMS memory and if
  711.           there's enough memory to save the program it goes to EMS.  If
  712.           there isn't any EMS memory (or there isn't enough remaining to
  713.           switch to) Switch! will create a disk file.  This means you don't
  714.           have to worry about whether the target machine has EMS.  Switch!
  715.           will automatically look for it when called.
  716.  
  717.           _________________________________________________________________
  718.  
  719.           1. The Turbo Linker ((TM) Borland International) was used with
  720.              the demo program for Clipper to come up with the 7-8K value.
  721.  
  722.  
  723.  
  724.                                        - 11 -
  725.  
  726.  
  727.  
  728.  
  729.  
  730.  
  731.  
  732.  
  733.           5.6  Tips on Using Switch!
  734.  
  735.  
  736.           Switch! can work in most applications, but some will require a
  737.           little attention.  If your program takes over any interrupts you
  738.           should include the module containing the interrupt handler BEFORE
  739.           Switch!.  For example, assuming the ASYNC.OBJ module contained an
  740.           interrupt handler:
  741.  
  742.                CORRECT:
  743.  
  744.                link ASYNC SWITCH,,, (etc...)
  745.  
  746.                INCORRECT:
  747.  
  748.                link SWITCH ASYNC,,, (etc...)
  749.  
  750.           The second example is incorrect because when Switch! is called it
  751.           could free the memory used by the interrupt handler.  While the
  752.           memory is free an interrupt might be generated causing lockup
  753.           since the interrupt handler no longer resides at the place
  754.           pointed to by the interrupt address table.  If you are sure no
  755.           interrupts can occur while you are "Switched!" out there isn't a
  756.           problem.
  757.  
  758.  
  759.  
  760.  
  761.  
  762.  
  763.  
  764.  
  765.  
  766.  
  767.  
  768.  
  769.  
  770.  
  771.  
  772.  
  773.  
  774.  
  775.  
  776.  
  777.  
  778.  
  779.  
  780.  
  781.  
  782.  
  783.  
  784.  
  785.  
  786.  
  787.  
  788.  
  789.  
  790.                                        - 12 -
  791.  
  792.  
  793.  
  794.  
  795.  
  796.  
  797.  
  798.  
  799.  
  800.  
  801.  
  802.  
  803.  
  804.  
  805.                                       Chapter 6
  806.  
  807.                                 Switch! Return Values
  808.  
  809.  
  810.           The value returned by Switch! (and Switch87!) indicate whether an
  811.           error occurred.  There are many possible errors that fall into a
  812.           few classifications of severity.  This Chapter lists the return
  813.           values, their meanings, and severity/classification of the error.
  814.           The suggested corrective actions are simple.  I'll list them by
  815.           classification.
  816.  
  817.           Classification      Suggested Action
  818.           --------------      ----------------
  819.           Severe              This is the type of error that occurs if
  820.                               Switch! can't successfully write the temp
  821.                               file to disk or EMS.  You should either
  822.                               ignore this error or print a message advising
  823.                               the execution of the called program couldn't
  824.                               be completed.  (These are Warning
  825.                               indicators).
  826.  
  827.           Critical            The action suggested for this class of error
  828.                               is simple.  You should IMMEDIATELY terminate
  829.                               the program.  If a critical error occurs it
  830.                               is unpredictable how much if any of the
  831.                               memory was able to be properly restored.
  832.                               (You shouldn't call ANY functions linked in
  833.                               after SWITCH was in the application).
  834.  
  835.           Fatal               The action suggested for this class is a
  836.                               reboot of the machine.  If a fatal error
  837.                               occurs odds are high that execution will not
  838.                               even be able to get back to the part of the
  839.                               program that called Switch!.
  840.  
  841.           Out of the classes of errors listed above there is only one that
  842.           can be reliably dealt with by your application - Severe.
  843.           Critical errors may be able to be dealt with, but the odds are
  844.           going against you.
  845.  
  846.           Okay, now that I've covered the various classes of errors let's
  847.           go over the return values from Switch!.
  848.  
  849.  
  850.  
  851.  
  852.  
  853.  
  854.  
  855.  
  856.                                        - 13 -
  857.  
  858.  
  859.  
  860.  
  861.  
  862.  
  863.  
  864.  
  865.           Return
  866.           Value     Description
  867.           ------    -----------
  868.             0       No errors occurred.  This is what you want!
  869.  
  870.             4       Too many open files.  This means that the DOS maximum
  871.                     number of files that can be open at once is exceeded by
  872.                     the request to open the temp file.  The way to fix this
  873.                     is to increase the number of files in config.sys
  874.                     FILES=15, or to close some of the open files in your
  875.                     application.  <SEVERE>
  876.  
  877.             5       Access Denied.  This means that the root directory of
  878.                     the disk to store the temp file is already full.
  879.                     Switch! creates the temp file in the root directory
  880.                     (the temp file is hidden).  <SEVERE>
  881.  
  882.             7       Memory control blocks are damaged.  This means it's
  883.                     probably time to reboot the machine!   <CRITICAL>
  884.  
  885.             8       Not enough memory to reload the original program.  This
  886.                     error could be caused if the user loads a TSR or other
  887.                     program and then exits back to the first application.
  888.                     <FATAL>.
  889.  
  890.             249     Invalid Drive.  This error means the drive specified to
  891.                     create the temp file on is invalid.  <SEVERE>
  892.  
  893.             250     Not enough disk space.  This error means the drive
  894.                     to store the temp file on doesn't have enough free
  895.                     space save the file (Switch! checks the disk space
  896.                     before attempting to create the file).  <SEVERE>
  897.  
  898.             251     Error reading EMS.  This error means that an error
  899.                     occurred while Switch! was restoring the program from
  900.                     EMS.  <CRITICAL>
  901.  
  902.             252     Can't locate COMMAND.COM.  This error means that
  903.                     Switch! couldn't locate COMMAND.COM using the COMSPEC
  904.                     environment variable.  (COMMAND.COM must be available
  905.                     for Switch! to execute a program).  <SEVERE>
  906.  
  907.             253     Temp file is missing on restore!  This error means that
  908.                     the disk with the temp file was removed (or the user
  909.                     deleted the temp file).  <CRITICAL>
  910.  
  911.             254     Can't unallocate memory.  This means that Switch! can't
  912.                     deallocate the memory used by your application.
  913.                     <SEVERE>
  914.  
  915.             255     Unable to read file.  This means that an error occurred
  916.                     while reading the temp file back to memory.  <CRITICAL>
  917.  
  918.  
  919.  
  920.  
  921.  
  922.                                        - 14 -
  923.  
  924.  
  925.  
  926.  
  927.  
  928.  
  929.  
  930.  
  931.           As you can see there are quite a few different return values.
  932.           Luckily the odds are against the critical errors occurring (but
  933.           they are possible).  The odds against the fatal errors are even
  934.           higher (with the exception of a user possibly loading a TSR while
  935.           in the "shell").
  936.  
  937.  
  938.  
  939.  
  940.  
  941.  
  942.  
  943.  
  944.  
  945.  
  946.  
  947.  
  948.  
  949.  
  950.  
  951.  
  952.  
  953.  
  954.  
  955.  
  956.  
  957.  
  958.  
  959.  
  960.  
  961.  
  962.  
  963.  
  964.  
  965.  
  966.  
  967.  
  968.  
  969.  
  970.  
  971.  
  972.  
  973.  
  974.  
  975.  
  976.  
  977.  
  978.  
  979.  
  980.  
  981.  
  982.  
  983.  
  984.  
  985.  
  986.  
  987.  
  988.                                        - 15 -
  989.  
  990.  
  991.  
  992.  
  993.  
  994.  
  995.  
  996.  
  997.  
  998.  
  999.  
  1000.  
  1001.  
  1002.  
  1003.                                       Chapter 7
  1004.  
  1005.                                      Background
  1006.  
  1007.  
  1008.           There are several reasons why I developed Switch!.  First off, I
  1009.           do systems analysis/programming for a living.  A lot of work I do
  1010.           involves large data base applications in a network environment.
  1011.           By the time you add in the memory required by the average
  1012.           application I'm working on with the high overhead for the network
  1013.           software that is resident it is common to not even have enough
  1014.           memory left over to execute a DOS shell (that really hurts the
  1015.           application when you consider that to link to any of the network
  1016.           drives/printers a DOS command needs to be executed).  Finally
  1017.           after getting frustrated with 640K not being enough memory I
  1018.           created Switch! to solve the memory shortage problems.
  1019.  
  1020.  
  1021.  
  1022.  
  1023.  
  1024.  
  1025.  
  1026.  
  1027.  
  1028.  
  1029.  
  1030.  
  1031.  
  1032.  
  1033.  
  1034.  
  1035.  
  1036.  
  1037.  
  1038.  
  1039.  
  1040.  
  1041.  
  1042.  
  1043.  
  1044.  
  1045.  
  1046.  
  1047.  
  1048.  
  1049.  
  1050.  
  1051.  
  1052.  
  1053.  
  1054.                                        - 16 -
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060.  
  1061.  
  1062.  
  1063.  
  1064.  
  1065.  
  1066.  
  1067.  
  1068.  
  1069.                                      Appendix A
  1070.  
  1071.                               Example Calls to Switch!
  1072.  
  1073.  
  1074.           This appendix will show an example of calling switch for C,
  1075.           assembly, and Clipper.
  1076.  
  1077.           C Example:
  1078.  
  1079.                drive = 0;               /* assume current drive */
  1080.                memrequired = 64;             /* free 64K of memory */
  1081.  
  1082.                /* call Switch! to execute TED to edit names.txt */
  1083.                switch_( drive, memrequired, "TED names.txt" );
  1084.  
  1085.  
  1086.           Assembly Example:
  1087.           ;
  1088.           ;    This example assumes that DS:SI point to the command line
  1089.           ;    to execute with Switch!.
  1090.           ;
  1091.           EXTRN _switch_
  1092.  
  1093.                push si             ;pass parameters in C convention
  1094.                push ds             ;(backwards).  Push command_line
  1095.                xor ax,ax           ;address first.
  1096.                push ax             ;push memrequired - 0 means save all
  1097.           possible.
  1098.                push ax             ;push drive - 0 means current drive.
  1099.                call far ptr _switch_    ;execute the command
  1100.                or al,al            ;check for error
  1101.                jne handle_error    ;non-zero return means there was an
  1102.                                    ;error!
  1103.  
  1104.  
  1105.           Clipper Example:
  1106.  
  1107.                ** In this example I'll duplicate the C example using
  1108.                ** Clipper Code
  1109.  
  1110.                drive = 0           && Assume the current drive
  1111.                memrequired = 64              && Free 64K memory
  1112.  
  1113.                ** Now call switch87 to execute TED to edit names.txt
  1114.                ** Note that although the drive parameter is optional
  1115.                ** and defaults to 0 it is required in this example
  1116.                ** because the memrequired is being specified.  Remember the
  1117.  
  1118.  
  1119.  
  1120.                                        - 17 -
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126.  
  1127.  
  1128.  
  1129.                ** first numeric parameter is considered to be the drive.
  1130.  
  1131.                switch87( drive, memrequired, "TED names.txt" )
  1132.  
  1133.  
  1134.           Turbo Pascal Example: (type CLINE is assumed to be defined as a
  1135.           string containing 80 characters!).
  1136.  
  1137.                {$F+}
  1138.                function Switch(drive : integer; mem : integer; command :
  1139.                     CLINE) : integer;   external;
  1140.  
  1141.                {$L switchtp}
  1142.                {$F-}
  1143.  
  1144.                drive := 0;              (* assume current drive *)
  1145.                memrequired := 64;       (* free 64K of memory *)
  1146.  
  1147.                (* call Switch! to execute TED to edit names.txt *)
  1148.                switch( drive, memrequired, "TED names.txt" );
  1149.  
  1150.  
  1151.           The demo programs included with Switch! also show the use of
  1152.           Switch!.
  1153.  
  1154.  
  1155.  
  1156.  
  1157.  
  1158.  
  1159.  
  1160.  
  1161.  
  1162.  
  1163.  
  1164.  
  1165.  
  1166.  
  1167.  
  1168.  
  1169.  
  1170.  
  1171.  
  1172.  
  1173.  
  1174.  
  1175.  
  1176.  
  1177.  
  1178.  
  1179.  
  1180.  
  1181.  
  1182.  
  1183.  
  1184.  
  1185.  
  1186.                                        - 18 -
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192.  
  1193.  
  1194.  
  1195.  
  1196.  
  1197.  
  1198.  
  1199.  
  1200.  
  1201.                                         Index
  1202.  
  1203.  
  1204.                  B                           freeing
  1205.                  BASIC                          more memory 10
  1206.                     example link line 10     function
  1207.                     function name 8             name for BASIC 8
  1208.                  BASIC object file 3            name for C 8
  1209.  
  1210.                  C                           I
  1211.                  C                           interrupts
  1212.                     example link line 10        special
  1213.                     function name 8             considerations 12
  1214.                  C/Assembly object file
  1215.                     3                        L
  1216.                  calling Switch!             languages supported 3
  1217.                     examples 17              License agreement 5
  1218.                  Clipper                     link line
  1219.                     example link line 10        example for BASIC 10
  1220.                     function name 8             example for C 10
  1221.                     version supported 9         example for Clipper
  1222.                  Clipper object file 3          10
  1223.                  command_line parameter      Linking Switch! to
  1224.                     9                           applications 10
  1225.                  considerations
  1226.                     interrupts 12            M
  1227.                                              memory
  1228.                  D                              freeing more 10
  1229.                  description                    tips to free more 10
  1230.                     of parameters 8          memory models supported
  1231.                  drive parameter                3
  1232.                     meaning 8                memrequired parameter 8
  1233.                                              models supported 3
  1234.                  E
  1235.                  EMS                         N
  1236.                     support for 7, 11        name
  1237.                     use of 11                   function for BASIC 8
  1238.                  example                        function for C 8
  1239.                     calls to Switch! 17         function for Clipper
  1240.                     link line for BASIC         8
  1241.                     10                          function for Turbo
  1242.                     link line for               Pascal 8
  1243.                     Clipper 10               name for Clipper 8
  1244.                                              name for Turbo Pascal 8
  1245.                  F                           Network use 11
  1246.                  files
  1247.                     object 3                 O
  1248.                                              object files 3
  1249.  
  1250.  
  1251.  
  1252.                                        - 19 -
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258.  
  1259.  
  1260.  
  1261.                     linking 10                  use on a network 11
  1262.                  optional                    SWITCH87.OBJ
  1263.                     parameters for              Clipper 3
  1264.                     Clipper 9                Switch! parameters 8
  1265.                                              Switch! return value 9
  1266.                  P                           Switch! return values
  1267.                  parameters                     13
  1268.                     Clipper notes 9          SWITCH.OBJ
  1269.                     command_line 9              C/Assembly 3
  1270.                     drive 8                  SWITCHQB.OBJ
  1271.                     memrequired 8               BASIC 3
  1272.                     ret_val (BASIC ONLY)     SWITCHTP.OBJ
  1273.                     9                           Turbo Pascal 3
  1274.                  parameters for Switch!      system
  1275.                     8                           requirements 2
  1276.  
  1277.                  R                           T
  1278.                  requirements                Turbo Pascal
  1279.                     system 2                    function name 8
  1280.                  ret_val parameter              linking in Switch!
  1281.                     (BASIC ONLY) 9              10
  1282.                  return value                Turbo Pascal object
  1283.                     for Switch! 9               file 3
  1284.                  return values
  1285.                     meanings 13              V
  1286.                                              version
  1287.                  S                              Clipper supported 9
  1288.                  Switch!
  1289.                     tips 12                  W
  1290.                                              Warranty 6
  1291.  
  1292.  
  1293.  
  1294.  
  1295.  
  1296.  
  1297.  
  1298.  
  1299.  
  1300.  
  1301.  
  1302.  
  1303.  
  1304.  
  1305.  
  1306.  
  1307.  
  1308.  
  1309.  
  1310.  
  1311.  
  1312.  
  1313.  
  1314.  
  1315.  
  1316.  
  1317.  
  1318.                                        - 20 -
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324.  
  1325.  
  1326.  
  1327.  
  1328.  
  1329.  
  1330.  
  1331.  
  1332.  
  1333.                                     Contents
  1334.  
  1335.  
  1336.  
  1337.                Chapter 1  Introduction                               2
  1338.                   1.1  What you should read  . . . . . . . . . . . . 2
  1339.                   1.2  Ok, Back to the Introduction  . . . . . . . . 2
  1340.                   1.3  Program Requirements  . . . . . . . . . . . . 2
  1341.                   1.4  Languages Supported . . . . . . . . . . . . . 3
  1342.                   1.5  Models Supported  . . . . . . . . . . . . . . 3
  1343.  
  1344.                Chapter 2  Registering Switch!                        4
  1345.                   2.1  Registration Benefits . . . . . . . . . . . . 4
  1346.                      2.1.1  Registration for Businesses  . . . . . . 4
  1347.  
  1348.                Chapter 3  License                                    5
  1349.  
  1350.                Chapter 4  Warranty                                   6
  1351.  
  1352.                Chapter 5  Using Switch!                              7
  1353.                   5.1  How It Works  . . . . . . . . . . . . . . . . 7
  1354.                   5.2  Using Switch! . . . . . . . . . . . . . . . . 8
  1355.                      5.2.1  CLIPPER NOTES  . . . . . . . . . . . . . 9
  1356.                   5.3  Linking Switch! in Your Applications  . . .  10
  1357.                   5.4  Switch! on a Network  . . . . . . . . . . .  11
  1358.                   5.5  Should I Switch! to EMS or Disk?  . . . . .  11
  1359.                   5.6  Tips on Using Switch! . . . . . . . . . . .  12
  1360.  
  1361.                Chapter 6  Switch! Return Values                     13
  1362.  
  1363.                Chapter 7  Background                                16
  1364.  
  1365.                Appendix A  Example Calls to Switch!                 17
  1366.  
  1367.                Index                                                19
  1368.  
  1369.  
  1370.  
  1371.  
  1372.  
  1373.  
  1374.  
  1375.  
  1376.  
  1377.  
  1378.  
  1379.  
  1380.  
  1381.  
  1382.  
  1383.  
  1384.                                           i
  1385.  
  1386.  
  1387.