home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR13 / TI_BC1.ZIP / TI1704.ZIP / TI1704.ASC
Text File  |  1993-10-12  |  5KB  |  265 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Borland C++                           NUMBER  :  1704
  9.   VERSION  :  3.X
  10.        OS  :  WIN, DOS
  11.      DATE  :  October 12, 1993                         PAGE  :  1/4
  12.  
  13.     TITLE  :  Detecting whether SHARE is loaded
  14.  
  15.  
  16.  
  17.  
  18.   //--------------------------------------------------------------
  19.   //
  20.   //  Due to complications under Windows 3.x, SHARE can no longer
  21.   //  be detected with certainty using int 2Fh Function 1000h.
  22.   //
  23.   //  The published workaround is to create a temporary file,
  24.   //  and try to lock a section of it.  If the lock fails due
  25.   //  to an "Invalid function number" (i.e. dos error code 1 )
  26.   //  then SHARE is not loaded.
  27.   //
  28.   //  The following source is an example of doing this in C++.
  29.   //  The source was designed for the large memory model, but
  30.   //  can be compiled for the small memory model by modifying
  31.   //  CreateTempOn() as indicated in the source.
  32.   //
  33.   //
  34.   //  NOTE: The directory on which the shared files are located
  35.   //        is significant in a network environment.  Typically
  36.   //        share is loaded on the network server and is available
  37.   //        for files on network drives.  This is not necessarily
  38.   //        true for local drives.
  39.   //--------------------------------------------------------------
  40.  
  41.   #include <errno.h>     // for errno and EINVAL
  42.   #include <io.h>        // for lock()
  43.   #include <string.h>    // for strlen() and strcpy()
  44.   #include <iostream.h>  // for cout
  45.  
  46.  
  47.   char *TempFilename;
  48.   int DetectShareOn( char *PathToSharedFiles );
  49.   int CreateTempOn( char *PathOfTempFile );
  50.   int DeleteTempFile( void );
  51.  
  52.  
  53.   int main(void)
  54.      {
  55.      char Directory[] = "C:\\";
  56.      switch ( DetectShareOn ( Directory ) )
  57.          {
  58.          case 1:
  59.              cout << "Share installed on " << Directory << endl;
  60.              return 0;
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  Borland C++                           NUMBER  :  1704
  75.   VERSION  :  3.X
  76.        OS  :  WIN, DOS
  77.      DATE  :  October 12, 1993                         PAGE  :  2/4
  78.  
  79.     TITLE  :  Detecting whether SHARE is loaded
  80.  
  81.  
  82.  
  83.  
  84.          case 0:
  85.              cout << "Share not installed on " << Directory
  86.                   << endl;
  87.              return 1;
  88.  
  89.          default:
  90.              cout << "Error in detection." << endl;
  91.              return 2;
  92.          }
  93.      }
  94.  
  95.  
  96.   int DetectShareOn( char *PathToSharedFiles )
  97.   // Parameter:
  98.   //     PathToSharedFiles - null-terminated string containing
  99.   //                         path to shared files
  100.      {
  101.      int RetValue;
  102.      int TempHandle = CreateTempOn( PathToSharedFiles );
  103.      if ( !TempHandle )
  104.          return -1;
  105.  
  106.      switch (lock( TempHandle, 0, 1 ))
  107.          {
  108.          case -1:
  109.              if ( errno == EINVAL )
  110.                  RetValue = 0;
  111.              else
  112.                  RetValue = -1;
  113.              break;
  114.  
  115.          default:
  116.              unlock ( TempHandle, 0, 1 );
  117.              RetValue = 1;
  118.          }
  119.  
  120.      DeleteTempFile();
  121.      return RetValue;
  122.      }
  123.  
  124.  
  125.   int CreateTempOn( char *PathOfTempFile )
  126.   // Parameter:
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.   PRODUCT  :  Borland C++                           NUMBER  :  1704
  141.   VERSION  :  3.X
  142.        OS  :  WIN, DOS
  143.      DATE  :  October 12, 1993                         PAGE  :  3/4
  144.  
  145.     TITLE  :  Detecting whether SHARE is loaded
  146.  
  147.  
  148.  
  149.  
  150.   //     PathOfTempFile - null-terminated string containing
  151.   //                      path to create temporary file
  152.      {
  153.      TempFilename = new char [ strlen(PathOfTempFile) + 13 ];
  154.      if ( !TempFilename )
  155.          return 0;
  156.      strcpy( TempFilename, PathOfTempFile );
  157.  
  158.   asm    push    ds
  159.   asm    xor     cx, cx
  160.   asm    mov     dx, word ptr TempFilename
  161.  
  162.      // Remove the following two lines for near memory models
  163.   asm    mov     ax, word ptr TempFilename + 2
  164.   asm    mov     ds, ax
  165.  
  166.   asm    mov     ax, 5a00h
  167.   asm    int     21h
  168.   asm    pop     ds
  169.   asm    jc      CreateTempFailed
  170.      return (_AX);
  171.  
  172.   CreateTempFailed:
  173.      return 0;
  174.      }
  175.  
  176.  
  177.   int DeleteTempFile( void )
  178.      {
  179.      int RetValue = remove ( TempFilename );
  180.      switch ( RetValue )
  181.          {
  182.          case 0:
  183.              delete TempFilename;
  184.              return RetValue;
  185.  
  186.          default:
  187.              return RetValue;
  188.          }
  189.      }
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.   PRODUCT  :  Borland C++                           NUMBER  :  1704
  207.   VERSION  :  3.X
  208.        OS  :  WIN, DOS
  209.      DATE  :  October 12, 1993                         PAGE  :  4/4
  210.  
  211.     TITLE  :  Detecting whether SHARE is loaded
  212.  
  213.  
  214.  
  215.  
  216.   DISCLAIMER: You have the right to use this technical information
  217.   subject to the terms of the No-Nonsense License Statement that
  218.   you received with the Borland product to which this information
  219.   pertains.
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.