home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Internet Business Development Kit / PRODUCT_CD.iso / sqlsvr / odbcsdk / drvsetup.kit / _bootstp.c next >
Encoding:
C/C++ Source or Header  |  1994-12-07  |  5.1 KB  |  220 lines

  1. /******************************************************************************
  2.  *
  3.  *  _BOOTSTP.C
  4.  *  Copyright (C) 1993, Microsoft Corp.
  5.  *  All Rights Reserved.
  6.  *
  7.  ******************************************************************************
  8.  *
  9.  *  Description:    Extremely simple 16-bit bootstrapper for the 32-bit
  10.  *                  setup executable.  This is only necessary so that the
  11.  *                  DOS setup bootstrapper can detect when the program is
  12.  *                  done so that it can clean up the temporary directory.
  13.  *
  14.  ******************************************************************************
  15.  *
  16.  *  Contains:       WinMain
  17.  *                  WndProc
  18.  *
  19.  ******************************************************************************
  20.  *
  21.  *  Known Bugs:     none
  22.  *
  23.  ******************************************************************************
  24.  *
  25.  *  Possible Improvements:
  26.  *
  27.  ******************************************************************************
  28.  *
  29.  *  Revision History:
  30.  *
  31.  *  none
  32.  *
  33.  *****************************************************************************/
  34.  
  35.  
  36.  
  37.     //
  38.     //  Headers
  39.     //
  40.  
  41. #define STRICT
  42. #include <windows.h>
  43. #include <stdlib.h>
  44. #include "drvsetup.h"
  45.  
  46.  
  47.  
  48.     //
  49.     //  Constants
  50.     //
  51.  
  52. const char    ODBCCLASS[]        = ODBCSETUPCLASS;
  53. const char    *BOOTCLASS      = "ODBC_BOOTSTRAP";
  54. const char    *BOOTWINDOW     = "Bootstrapper";
  55. #define        ID_TIMER        1
  56. #define        TIMER_GRAN        100
  57.  
  58.  
  59.     //
  60.     //    Globals
  61.     //
  62.  
  63. BOOL    fStarted            = FALSE;
  64. UINT    nTicks                = 0;
  65.  
  66.  
  67.  
  68.  
  69. //
  70. //  WndProc
  71. //
  72. //      Simple windows procedure to process the timer messages.
  73. //
  74. LRESULT CALLBACK WndProc(HWND   hwnd,
  75.                          UINT   wmsg,
  76.                          WPARAM wParam,
  77.                          LPARAM lParam)
  78.     {
  79.     switch( wmsg )
  80.         {
  81.         case WM_TIMER:
  82.  
  83.             if( !fStarted )
  84.                 {
  85.                     //
  86.                     //    If we've waited for more than approx. 5 seconds
  87.                     //    and the app hasn't started yet, we'll assume that
  88.                     //    it's never going to and that we should abort
  89.                     //
  90.  
  91.                 if( nTicks * TIMER_GRAN >= 5000 )
  92.                     {
  93.                     PostMessage(hwnd, WM_CLOSE, 0, 0L);
  94.                     break;
  95.                     }
  96.                     
  97.                 if( FindWindow(ODBCCLASS, NULL) )
  98.                     fStarted = TRUE;
  99.                 else
  100.                     nTicks++;
  101.                 }
  102.             else if( !FindWindow(ODBCCLASS, NULL) )
  103.                 PostMessage(hwnd, WM_CLOSE, 0, 0L);
  104.             break;
  105.  
  106.         case WM_DESTROY:
  107.             KillTimer(hwnd, ID_TIMER);
  108.             PostQuitMessage(0);
  109.             break;
  110.  
  111.         default:
  112.             return DefWindowProc(hwnd, wmsg, wParam, lParam);
  113.         }
  114.  
  115.     return 0;
  116.     }
  117.  
  118.  
  119.  
  120.  
  121. //
  122. //  WinMain
  123. //
  124. //      Windows entry point -- start up the 32-bit executable
  125. //      and wait for it to finish.
  126. //
  127. //
  128. int PASCAL WinMain(HINSTANCE  hInstance,
  129.                    HINSTANCE  hPrevInstance,
  130.                    LPSTR      lpszCmdLine,
  131.                    int        nCmdShow)
  132.     {
  133.     WNDCLASS    wc;
  134.     HWND        hwnd;
  135.     MSG         msg;
  136.  
  137.         //
  138.         //  Don't continue if there's another instance already running;
  139.         //  simply exit silently -- there's no need for TWO bootstrappers
  140.         //  to be running, executing, and waiting on the same program!
  141.         //
  142.  
  143.     if( hPrevInstance )
  144.         return FALSE;
  145.  
  146.         //
  147.         //  Make sure that the program we were planning on executing is
  148.         //  not already running for some reason.
  149.         //
  150.  
  151.     if( FindWindow(ODBCCLASS, NULL) )
  152.         return FALSE;
  153.  
  154.         //
  155.         //  Fill out the class structure
  156.         //
  157.  
  158.     wc.style            =   CS_HREDRAW | CS_VREDRAW;
  159.     wc.lpfnWndProc      =   WndProc;
  160.     wc.cbClsExtra       =   0;
  161.     wc.cbWndExtra       =   0;
  162.     wc.hInstance        =   hInstance;
  163.     wc.hIcon            =   NULL;
  164.     wc.hCursor          =   LoadCursor(NULL, IDC_ARROW);
  165.     wc.hbrBackground    =   (HBRUSH)(COLOR_BACKGROUND + 1);
  166.     wc.lpszMenuName     =   NULL;
  167.     wc.lpszClassName    =   BOOTCLASS;
  168.  
  169.         //
  170.         //  Register the class
  171.         //
  172.  
  173.     if( !RegisterClass(&wc) )
  174.         return FALSE;
  175.  
  176.         //
  177.         //  Create the window
  178.         //
  179.  
  180.     if( !(hwnd = CreateWindow(BOOTCLASS, BOOTWINDOW,
  181.                               WS_OVERLAPPEDWINDOW,
  182.                               CW_USEDEFAULT, CW_USEDEFAULT,
  183.                               CW_USEDEFAULT, CW_USEDEFAULT,
  184.                               HWND_DESKTOP,
  185.                               NULL,
  186.                               hInstance,
  187.                               NULL)) )
  188.         return FALSE;
  189.  
  190.         //
  191.         //  Register a timer
  192.         //
  193.  
  194.     if( !SetTimer(hwnd, ID_TIMER, TIMER_GRAN, NULL) )
  195.         return FALSE;
  196.  
  197.         //
  198.         //  Execute the new program
  199.         //
  200.  
  201.     if( WinExec(lpszCmdLine, SW_SHOW) < 32 )
  202.         return FALSE;
  203.  
  204.         //
  205.         //  Get and dispatch messages
  206.         //
  207.  
  208.     while( GetMessage(&msg, NULL, 0, 0) )
  209.         {
  210.         TranslateMessage(&msg);
  211.         DispatchMessage(&msg);
  212.         }
  213.  
  214.         //
  215.         //  Once the program has finished, we can return
  216.         //
  217.  
  218.     return TRUE;
  219.     }
  220.