A user of Prospero Pascal who has the Prospero DOS Extender Kit is able to
run simple Pascal programs under Windows 3. With appropriate declarations,
it is also possible to call API functions from Pascal, and with the aid of
the Microsoft Windows SDK such a user can produce applications which employ
Windows features such as graphical output, pull-down menus and dialog-boxes.
An appropriate version of the compiler is needed (see below), and a zip file
(P5-WIN.ZIP, ?? KB) is
available which contains the declaration and definition
files. While this software has been in use and is believed
correct, it is made available "as is", free of charge and without warranty.
Prospero will collate any corrections notified, but are not able to provide
assistance on techniques of Windows programming, which is the subject of
numerous books and articles.
Requirements
For the development of windows programs, Prospero Pascal version 5.23 and
the DOS Extender Kit version 2.11 or later are required.
The Pascal compiler in version 5.23 and later has an extra option, /w. This
option must be used when compiling any source files that contain functions
that may be used as call-back functions. The option puts the call-back
prologue and epilogue code into every outer-level procedure and function in
the program or segment. While this does not affect the working of code, it
increases size and degrades performance slightly, and it is therefore
recommended that where possible call-back functions are grouped together
in one segment.
The DOS Extender Kit version 2.11 and later is known to work with Windows 3.0
and 3.1.
For any serious Windows development work, the Microsoft SDK (or comparable
product) is essential. This includes tools such as the resource editor and
compiler and the SDKPaint utility. In addition, while the documentation in
the SDK is quite extensive, further books may also be found helpful.
Supplied Software
The zipfile contains a number of files, including a model Windows program with some
graphical output, pull-down menus and dialog-boxes. With the Prospero products and the
Microsoft SDK it is possible to build this program. The files associated with each stage, up
to the executable program, are included for purposes of assessment.
nothing.pas Sample source file nothing.dlg Dialog definition created by resource editor of SDK nothing.h (as above) nothing.rc Resource script file nothing.def Definitions file for linking "nothing" nothing.inc Pascal equivalent to nothing.h, generated by def2const.exe (see below). nothing.obj Compiled model program. nothing.exe The completed model program. windows.inc Pascal equivalent of windows.h. windata.pas Pascal include file defining a common block containing useful data. def2const.exe Simple utility to convert C #defines to Pascal CONST definitions. def2const.pas Source of above.
Producing an application
These files illustrate the steps in the process of creating the "nothing" program.
First nothing.dlg and nothing.h were created with the resource editor from the Microsoft
SDK. The supplied def2const program was then used to create a nothing.inc from the
nothing.h, turning C #defines into equivalent Pascal CONST definitions.
def2const nothing
The source file nothing.pas names three include files: windows.inc (a Pascal equivalent of
windows.h), nothing.inc and windata.pas (defining a common block containing useful data).
As this source file contains windows call-back routines, it must be compiled using at least the
option /w.
propas nothing /wg
The file nothing.def contains the two call-back routines in its list of exports. Otherwise it is
the same as the file win.def supplied with the DOS Extender Kit.
ppmlink /n nothing wpaslib nothing/d
Finally, the resource compiler from the SDK is used to bind in the resources.
rc nothing
The nothing.exe program produced is a model windows application, capable of being
adapted and extended in many different ways.
Programming Points
The majority of descriptions of Windows applications give examples in C which are readily
converted to Pascal. One consideration is that most of the routines declared in windows.inc
are functions, but in C code the result returned is sometimes ignored; in Pascal the result
must be assigned or otherwise used. The simplest equivalent is to assign to a dummy
variable, but an IF statement with empty THEN part is slightly more efficient:
if winfunc(...)=0 then;
The Windows functions in windows.inc are declared as OSExtern. As described in the
Pascal user manual and READ.ME, there is some relaxation of normal Pascal checking when
such routines are called, and advantage can be taken of these, for instance:
· For a value Asciiz parameter, a literal may be given and the null terminator is supplied.
· For a VAR Asciiz parameter, NIL or a variable of type ptr may be given.
Other programming considerations include:
· NULL is defined as 0. This is not the same as NIL, and the two are not inter-changeable.
The Pascal heap uses global memory.
· It is possible to use readln and writeln, in particular for debugging. The stdin/stdout
window is opened automatically on the first read or write. Pascal run-time errors are
reported, including line numbers if the right compiler option is used. The stack traceback
stops at any call-back routine.
· Microsoft recommend a minimum stack size of 5K. Under the Prospero model, the stack
is in its own segment, so there are no great penalties if a much larger stack is used.