About the Windows interface with Dos
Note: Windows is a trademark of Microsoft Corporation.
Most of this information has NOT been tested by the author.
Please see disclaimer on main page.
What is Windows?
There are two 'flavours' of Windows: One is called 'NT', for 'New Technology', and the other generally goes under the name of 'Windows x.xx' (where x.xx is a version number, the most recent being 3.11; versions below 3.0 barely exist; 3.0 itself is rare; 3.1 was the next version after 3.0) or 'Windows 9x' (where x, together with the 9, give the year in the 20th century in which the version was released. The first released was 95, which supersedes Windows 3.11, but Microsoft have announced plans to release Windows 98, which will be the next version).
Windows NT is an operating system in its own right. Windows x.xx runs 'on top of' MS-DOS (or compatible DOS). Windows 95 claims to be an operating system in its own right, as it comes with a version of DOS specifically tailored to support it (known as DOS 7.0). Essentially, however, Windows 9x operates in exactly the same way as Windows x.xx - it can be considered to be 'running on top of DOS'. For this reason, they will be referred to as 'WinDos' from here on. NT, on the other hand, while it does provide the ability to run DOS programs, does so in a limited environment; it will not be discussed here.
WinDos is a multi-tasking operating system. It is capable of running multiple programs at once. The term 'program' here refers to either a 'native Windows application' or a DOS application(s) running in a 'DOS box'. The DOS boxes are each run in their own 'virtual machine' (VM), so called because devices are virtualised to avoid clashes (the video display, for instance: only the active application will be able to modify the display. Other VMs may make writes to the screen, but Windows traps these, only allowing them to be performed when the VM becomes the active VM.
Windows works by putting the processor in protected mode. This enables it to assume more control than is possible in real mode and may also allow the use of Virtual '86 mode to run DOS-based tasks. In Windows x.xx, There are two 'modes' in which Windows can operate: 'Standard mode' (for 286s) and 'Enhanced Mode' (for 386s, enables 32-bit code and V86 mode). In standard mode, it is necessary for Windows to maintain a temporary disk file for each DOS-based task, and it is necessary for the processor to switch to real mode to allow running time for these tasks. Windows 9x operates only in enhanced mode.
What does Windows provide?
- A multi-tasking operating system for the user
- An API with functions for various purposes for the programmer
- Device drivers with standard APIs for access to devices such as video, printers, mice, keyboards.
- Standard data and file formats for the programmer and user
- A standard user interface encouraged by the API and structure of Windows.
Multi-tasking abilities include:
- The ability to run several tasks at once, and to switch between tasks
- Some protection against dangerous or apparently erroneous activity by programs
- A 'clipboard' which is essentially a data area used to transfer data between different applications, usually under the control of the user
- DDE (Dynamic Data Exchange) to allow communication between applications, usually without overseeing by the user
- OLE (Object Linking and Embedding) to allow data or sections of data from one application to be incorporated into another application such that the data appears as was intended in the original application, remains editable by the original application, and can possibly still be edited completely seperately from the target application.
Of the three data sharing techniques, only the clipboard is accessible to DOS applications. Task switching is usually initiated by the user. Windows in enhanced mode will provide 16 and 32-bit DPMI services to DOS programs.
What Windows does...
- Generates an 'initialization broadcast' to allow loaded DOS programs to recognize that window is being started and take advantage of the services offered.
- Runs through its initialization files (WIN.INI and SYSTEM.INI) in order to find the settings that the user requires. Windows may load its own device drivers during this time. In particular, the 'Virtual Device Drivers' are loaded. VxDs (as they are known) are used (amongst various other purposes) to prevent conflict of device access between concurrently executing VMs.
While windows is running, it may create virtual machines. Each VM is based on the state of the DOS system before Windows is started. Most of the already allocated memory has global scope - that is, if it is altered from any VM, the changes will be reflected in all other VMs (including the real mode DOS - the effects will be visible here after Windows is exited). VDDs
and TSRs which were able to hook the init broadcast may have or instantiate local data, and any new programs started within the VM will automatically have local data.
Detecting Windows
Any of the following methods may be used:
- Check the environment for a variable named 'windir' (lower case). It will contain the directory in which the main windows executables reside (eg, C:\WINDOWS). This is a very reliable method of checking the existence of Windows.
- With AX of 1600h, execute INT 2Fh. The return can reveal if enhanced mode windows is running, and if so, what version. If AL contains 80h or FFh it can be assumed that enhanced mode windows is not running; if AL is less than 3 the same is true. Any other value means that AL now contains a 'major' version number (the part of the version before the period) and AH contains a 'minor' version number. Note that these numbers are values which should be converted to two-digit decimal; a value of AL=3, AH=0Ah for instance indicates version 03.10 (or 3.10).
- Windows also generates a 'broadcast' to real mode DOS when it is starting and again when shutting down (exiting). These can easily be trapped by an application. On starting up, Windows executes an INT 2Fh with AX=1605h, ES:BX and DS:SI = 0000:0000, CX = 0 and DX bit 0 = 0. On exiting, INT 2Fh with AX = 1606h, DX bit 0 = 0 is called. SEE BELOW FOR IMPORTANT DETAILS.
- Windows has a module which operates in real and v86 mode called 'WINOLDAP'. It allows DOS based applications to access the clipboard. The presence of WINOLDAP indicates the presence of Windows. See below for details.
- Windows 3.1 (and later) has an 'Identify windows version and type' call. AX = 160Ah; INT 2Fh. Return will be AX = 0 if function supported, BX = version (BH = major, BL = minor, convert to 2 digit decimal), CX = mode (2 = standard, 3 = enhanced).
- Windows 3.0 in standard mode returns CX as FFFFh and other registers unchanged if INT 2Fh called with AX = 1605h, ES:BX = DS:SI = 0:0, CX = 0, DX bit 0 = 0, DI = 0300h.
What not to do under Windows
- Don't try to enter protected mode directly. Windows in enhanced mode offers 32 and 16 bit DPMI services which you can use for that purpose. It should be safe to enter protected mode under standard mode Windows.
- When at all practical, use bios/dos/interrupt calls instead of accessing hardware directly. In particular, use DOS file handle functions (or FCBs if absolutely necessary) for all disk access; never modify the FAT directly. Of course, this is general good practice.
- If using super VGA graphics, use the VESA API if possible. You should also incorporate a 'screen refresh' command as windows cannot always restore high resolution screen modes correctly on a task switch. There appears to be no way to detect from within a VM when Windows has switched tasks.
- If performing something which should not be interrupted, it is possible to disable task switching for a short period of time, using the method outlined below.
- If a DOS program is idle (not currently performing an important task), it should (repeatedly until active) call INT 2Fh with AX = 1680h. This call is supported by other applications as well including some DPMI implementations and TSRs; AL will return with 0 if the function is indeed supported.
Service calls available to DOS programs
- Task switch enable/disable
- Windows start/exit broadcast
- WinOldAp services (clipboard access)
- Task Switch Disable:
AX = 1681h, INT 2Fh. Calls may be nested.
- Task Switch Enable:
AX = 1682h, INT 2Fh.
Windows start broadcast: AX = 1605h, ES:BX = 0:0, DS:SI = 0:0, CX = 0, DX bit 0 = 0, DI = windows version (major in upper bytes, minor in lower byte, convert each to 2 digit decimal for correct display), INT 2Fh: Called by Windows (enhanced mode) on startup. Set CX to any other value (1 - FFFFh) to avoid having windows load (exit broadcast will be sent immediately). Be careful to allow multiple programs to hook the broadcast (a program should always 'pass through' the interrupt before processing itself). DS:SI remains somewhat of a mystery to me; unless you know what it does, don't change it. ES:BX can be set to point to a 'startup info structure', which allows a program to create areas of memory which will contain data local to the VMs.
Windows exit broadcast: AX = 1606h, DX bit 0 = 0, Int 2Fh: Called by enhanced mode windows (in real mode) as it shuts down.
WINOLDAP services
This module (which is definitely supported by Windows 3.0+) allows access to
the windows clipboard. The clipboard is a data area accessible by all tasks.
It can simultaneously hold several different formats of information. These
are:
- 01 - text
- 02 - bitmap
- 07 - OEM text (application specific text; often RTF)
- (others available but details unknown)
Detecting WINOLDAP clipboard functions: AX = 1700h, INT 2Fh. If AX = 1700h
on return, functions are not supported, otherwise AL contains the major and
AH the minor version.
Putting data in the clipboard:
- Open the clipboard
- (recommended) empty the clipboard
- Set the data
- Close the clipboard
Retrieving data from the clipboard:
- Open the clipboard
- Get the data
- Close the clipboard
Functions are as follows:
- Open c/b: AX = 1701h, INT 2Fh. Nonzero AX indicates success; zero indicates
the clipboard is already open (by this or another task). The clipboard
cannot be accessed by any other task once it is opened.
- Empty c/b: AX = 1702h, INT 2Fh. Nonzero AX for sucess; other value means
an error occurred (the clipboard was not opened by this task).
- Set Data: AX = 1703h, DX = format, ES:BX = address of data, SI:CX = size of
data, INT 2Fh. Nonzero AX for success; failure due to clipboard not open
by this task, invalid format, not enough memory.
- Get data size: AX = 1704h, DX = format, INT 2Fh. DX:AX returns the size in
bytes, rounded up to a multiple of 32 (annoyingly enough), of the data
stored in the given format.
- Get data: AX = 1705h, DX = format, ES:BX = buffer, INT 2Fh. AX zero on
error, which could be: clipboard not open,
no data in specified format.
- Close c/b: AX = 1708h, INT 2Fh. AX = 0 on failure (not open).
Bitmap format:
(offset hex) (desc)
00 WORD 'type' (must = 0)
02 WORD width in pixels
04 WORD height in pixels
06 WORD bytes per line
08 BYTE number of colour planes
09 BYTE 'number of adjacent colour bits in pixel' (bits per pixel per plane)
0A DWORD pointer to start of bitmap data
0E WORD desired width in 0.1mm units (currently ignored)
10 WORD desired height in 0.1mm units (currently ignored)