home *** CD-ROM | disk | FTP | other *** search
/ Borland Programmer's Resource / Borland_Programmers_Resource_CD_1995.iso / code / bcpp / file14 / windet.c < prev   
Encoding:
C/C++ Source or Header  |  1995-05-19  |  1.2 KB  |  64 lines

  1.  
  2.  
  3. /***
  4. This code should detect the presense of Windows when run from a DOS
  5. application.  It doesn't detect Windows' real mode (which isn't
  6. supported under 3.1, and is of little advantage even under 3.0).
  7. ***/
  8.  
  9.  
  10. int windows_running( void)
  11.   {
  12.   asm mov  ax,160AH
  13.   asm int  2FH
  14.   asm or   ax,ax
  15.   asm jz   windows_found    /* Win 3.1 found */
  16.  
  17.   asm mov  ax,1600H
  18.   asm int  2FH
  19.   asm and  al,2FH
  20.   asm jnz  windows_found    /* Win 3.0 enhanced mode */
  21.  
  22.   asm mov  ax,4680H
  23.   asm int  2FH
  24.   asm or   ax,ax
  25.   asm jnz  windows_not_found
  26.  
  27.   asm sub  bx,bx
  28.   asm mov  es,bx
  29.   asm mov  di,bx
  30.   asm mov  ax,4B02H
  31.   asm int  2FH
  32.   asm or   ax,ax             /* DOS 5.0 Windows-like code running, */
  33.   asm jz   windows_not_found /* but it's not Windows */
  34.  
  35.   asm mov  ax,1605H
  36.   asm int  2FH
  37.   asm inc  cx
  38.   asm push cx
  39.   asm mov  ax,1606H
  40.   asm int  2FH
  41.   asm pop  cx
  42.   asm jcxz windows_found     /* Win 3.0 standard mode */
  43.  
  44. windows_not_found:
  45.   asm sub  ax,ax
  46.   goto end_windows_running;
  47.  
  48. windows_found:
  49.   asm mov  ax,1
  50.  
  51. end_windows_running:
  52.   return _AX;
  53.   }
  54.  
  55. #include <stdio.h>
  56.  
  57. main()
  58.   {
  59.   puts( ( windows_running()) ? "Windows Running" : "Windows not found");
  60.   return 0;
  61.   }
  62.  
  63.  
  64.