The S Library version 1.0


Windows95 support unit


The S Library Windows95 support unit allows your DOS programs to make full use 
of the long file names (255 characters) and long directory names (260 characters) 
that are used by Windows95.


Unit information


Program Title:	SWIN95 - Windows95 related functions.
External name: 	SWIN95.TPU
Version: 	1.0
Start date: 	20/2/97
Last update: 	22/2/97
Author: 	Rob Anderton.
Description: 	Windows95 support routines including long filename support.


System requirements


The only requirement is MS-DOS 7.0 (or the Windows95 command prompt). It is
possible that the unit will work with other Windows95 aware DOS versions.
This unit will not work with Microsoft Windows NT 4.0.


Data types


The following data types are defined in this unit.

- TVolumeInfo95
 
  PVolumeInfo95 = ^TVolumeInfo95;
  TVolumeInfo95 = record
 			wFlags		 : word;
			wFileNameLength	 : word;
			wDirectoryLength : word;
			sFileSystem	 : string;
		  end;

This record structure is used by the Win95_GetVolumeInfo procedure (see 
below). The wFlags fields is a bit field which contains specific information 
about the file system:

    Ŀ
     Bit(s)  Description                                         
    Ĵ
     0       searches are case sensitive                         
     1       preserves case in directory entries                 
     2       uses UniCode characters in file and directory names 
     3-13    reserved                                            
     14      supports DOS long filename functions                
     15      volume is compressed                                
    

Several constants are defined in the unit for use with this field, and they
are described later.

The wFileNameLength and wDirectoryLength define the maximum length of 
the ASCIIZ (null-terminated strings) used to store file and directory names. 

The sFileSystem field is a string used to store the file system description. 
Examples of the contents of this field include: 'FAT', 'NTFS' and 'CDFS'.


Global constants


The following constants are defined in the interface section of the unit for
use with the Windows95 procedures.

Ŀ
                                                                          
Constant name                  Value  Description                         
                                                                          
Ĵ
Win95_Volume_CaseSensitive     0001h  See above for details on the        
Win95_Volume_DirPreservesCase  0002h  TVolumeInfo95 record type.          
Win95_Volume_UniCode           0004h                                      
Win95_Volume_DOSLFNSupport     4000h                                      
Win95_Volume_Compressed        8000h                                      
Ĵ
Win95_TrueName                 True   Used by the filename functions to   
                                      determine whether a file on a drive 
                                      that has been SUBST'd has the SUBST 
                                      drive letter returned in its full                                               
                                      path name, or whether its true path 
                                      is returned (see below for more     
                                      information).                       
                                                                          



Procedures and functions


The following information describes the usage of the procedures and functions
defined in the unit. Please note that this unit makes use of the Turbo Pascal 
STRINGS unit and null-terminated strings. For more information of the STRINGS 
unit, look in the standard Pascal on-line help.

- Get volume information

procedure Win95_GetVolumeInfo(sRootDir : string;
                              var VolumeInfo : TVolumeInfo95);


This procedure uses interrupt 21h, function 71A0h to return information about a 
specified volume. This information includes the file system in use and the 
properties of file and directory names stored on the volume.

The sRootDir variable is used to determine which volume the procedure returns
information about. This can be in the form 'I:' or 'I:\', where 'I' is the
drive letter of the volume. If a drive letter doesn't exist the procedure
merely returns an empty record, and sets the error variable.

The VolumeInfo record is used to return the volume information. It is described
in more detail in the Data types section above.

- Get long filename

function Win95_GetLongFileName(var sShortFileName : string; 
                               bTruePath : boolean) : PChar;


This function takes the truncated DOS 8.3 filename and returns the Windows95
long filename as a null-terminated string.

For example: if sShortFileName is equal to 'C:\PROGRA~1\TESTFI~1.TXT' then 
this function would return 'C:\PROGRAMMING\TESTFILE95.TXT' as an ASCIIZ 
string.

The bTruePath parameter determines whether the path name returned should be 
the true path or the SUBST path (if SUBST is being used).

- Get short filename

function Win95_GetShortFileName(var pLongFileName : PChar;
                                bTruePath : boolean) : string;


This function does the opposite of the Win95_GetLongFileName function. An
ASCIIZ long filename is passed in the pLongFileName parameter, and a truncated 
DOS 8.3 filename is returned.

For example: if pLongFileName is equal to 'C:\PROGRAMMING\TESTFILE95.TXT' 
then this function would return 'C:\PROGRA~1\TESTFI~1.TXT' as a standard Pascal 
string.

bTruePath has the same meaning as for Win95_GetLongFileName.

- Rename file

procedure Win95_RenameFile(pOldFileName, pNewFileName : PChar);


This function renames a file using long filenames. pOldFileName is the current
name of the file, and pNewFileName is the new name of the file. Both parameters
are ASCIIZ strings.

- Create/open file

function Win95_CreateFile(pFileName : PChar; wFlags : word) : word;
function Win95_OpenFile(pFileName : PChar; wFlags : word) : word;

Both functions take a long filename, pFileName, and a flags parameter.
The table below shows details of wFlags.

    Ŀ
     Bit(s)  Description                                         
    Ĵ
      2-0    file access mode:                                   
              000 : read-only                                    
              001 : write-only                                   
              010 : read-write access                            
              100 : read-only (does not modify last access time) 
      3      reserved                                            
      6-4    file sharing modes:                                 
              000 : compatibility mode                           
              001 : "DENYALL" - no read/write access by others   
              010 : "DENYWRITE" - no write access by others      
              011 : "DENYREAD" - no read access by others        
              100 : "DENYNONE" - allow full access by others     
      7      do not inherit flag                                 
      8      do not buffer data                                  
      9      do compress data                                    
      10-14  unused by the unit                                  
    

The functions return 16bit DOS file handles which can be used with standard
DOS/Turbo Pascal handle based functions.

- Delete file

procedure Win95_DeleteFile(pFileName : PChar);


This function deletes the file with the long filename specified by pFileName, an
ASCIIZ parameter.

- Compressed file size

procedure Win95_CompressedFileSize(pFileName : PChar; 
                                   var lSize : longint);


This function returns the actual physical size of a compressed file. pFileName
is the name of the long filename, in ASCIIZ format, and lSize is the physical
file size in bytes.

- Get/set file attributes

procedure Win95_GetFileAttr(pFileName : PChar; var wAttr : word);
procedure Win95_SetFileAttr(pFileName : PChar; wAttr : word);


These two functions provide a way of setting extended file attributes for files
with long filenames. pFileName is the ASCIIZ long filename, and wAttr is a
bitfield describing file attributes such as hidden, system and read-only.
See the table below.

        Ŀ
        Bit(s)   Description                                 
        Ĵ                                                  
           7     sharable (Novell Netware)                   
           6     unused                                      
           5     archive                                     
           4     directory                                   
           3     volume label (execute-only, Novell Netware) 
           2     system                                      
           1     hidden                                      
           0     read-only                                   
        


- Get/set file write, access and creation time

procedure Win95_GetFileWriteTime(pFileName : PChar; var lTime : longint);
procedure Win95_SetFileWriteTime(pFileName : PChar; lTime : longint);

procedure Win95_GetFileAccessTime(pFileName : PChar; var lTime : longint);
procedure Win95_SetFileAccessTime(pFileName : PChar; lTime : longint);

procedure Win95_GetFileCreationTime(pFileName : PChar; var lTime : longint);
procedure Win95_SetFileCreationTime(pFileName : PChar; lTime : longint);


These functions allow you to get or set the different time stamps on files.
For all functions pFileName is the long filename of the required file and
lTime is the 4 byte packed time. This packed time can then be used with the
standard Turbo Pascal UnPackTime procedure.

The write time is the time the file was last written to, the access time is
the date of the last file access (the time is always returned as midnight)
and the creation time is the time that the file was created. The latter times
can be specified down to the nearest 10 milliseconds, but these functions do
not support this.

- Make, change and remove directories

procedure Win95_MakeDirectory(pDirName : PChar);
procedure Win95_RemoveDirectory(pDirName : PChar);
procedure Win95_ChangeDirectory(pDirName : PChar);


These procedures allow you to create, remove and change the current directory
to a specific directory using the long directory names. PDirName is the ASCIIZ
name of the directory.


Objects


The SWIN95 unit also includes a new object which is a descendent of the
TDOSStream object that is part of the Turbo Pascal OBJECTS unit. The object
is defined as shown below.

PDosStream95 = ^TDOSStream95;
TDOSStream95 = object(TDosStream)

  		  pName : PChar;

		  constructor Init(pFileName : PChar; wMode : word);

		  function GetPhysicalSize : longint; virtual;
		  function GetLongFileName : PChar;
		  function GetShortFileName : string;

               end;

The object works in basically the same way as the standard 
TDOSStream. The main difference being that the filename passed to 
the Init constructor is a long filename, and the object has a field 
which stores the filename.

New methods are the GetPhysicalSize method which calls 
Win95_CompressedFileSize procedure, GetLongFileName which simply 
returns the pName field, and GetShortFileName which calls 
Win95_GetShortFileName to convert the pName field into a DOS 8.3 
filename.


Limitations and bugs


This unit has been tested on a 486DX4 120MHz (described in the Test Systems 
section of the web pages) using Microsoft Windows95 Version 4.00.950a.

At present there are no known bugs. As this is not a completely 
complete unit, the SErrorCode variable is not used, and so no error
information is currently returned using the standard employed by 
other S Library units. This is because I am updating the error 
handling system, and will be changed for the next update. Error codes 
are however stored as in a global variable called wError, the codes 
are those returned by the DOS functions themselves (see a DOS 
reference manual for more information).


Future releases


Future releases of the unit will add proper error handling, support
for long filename searches (such as FindFirst and FindNext) and 
detection of the Windows95 operating system (this version just 
assumes Windows95 is running).


Acknowledgements and trademarks


This unit is part of the S Library, and is 1997 Rob Anderton.

The information used to write this unit and documentation comes from Ralph 
Brown's Interrupt List number 53 (see the Links section of the S Library web 
pages). 

Microsoft Windows95 is definitely a trademark of the Microsoft Corporation.

Novell Netware is probably a trademark of Novell.


