Varol Okan
The platform abstraction Layer is one of th most difficult parts to bring the application together. Rather then to change
all source code files, I decided to create a somewhat BASIC operating system interface which will provide the neccesary
OS calls for Windows and Linux.
The CPal class encapsulates system specific calls and make them available for other platforms (other then Microsoft's
Windows) through a more or less small software layer. Since it is based on the MS-Windows functionality, The layer
for MS-Windows is as thin as it can get. (See also the TWIN libraries)
Nevertheless it is neccesary to use this CPal class also with MS-Windows. Since the CPal class is so important, it is created at the startup of the application and destroyed at the termination of it.
A simple call to draw a line in a certain window I use :
pal.CDC.LineTo(x,y); rather then
myCDC.LineTo(x,y);
This aproach is highly Object oriented and can get transformed to other platforms as well as to other languages (JAVA)
fairly simple.
The CDC class is incorporated into the CPal class as well as the CWnd class. To create a new CDC object and attach it to
the CPal class one need to utilize the Add function of the CPal class.
E.g. CDC *pCDC = new CDC(); pal.Add(pCDC); Or in this simple case use the CreateNewDC() function pal.CraeteNewDC();
The error handling is somewhat complicated since I wanted to have the whole project language independend.
In order to display an error message one needs to involve the CError class. This class needs to be created
just once per session. It basically stores the english version of every error message in an internal
table. In order to receive the string in another language, it parses through an external ASCII file called :
errors.txt. This file has every message stored in different sections.
The English version looks something like :
[MISC]
ERROR_LOADING_ERROR=Error loading error messages. File 'errors.txt' contains corrupt data
[2DGFX]
ERROR_LOADING_TIFF=Error while loading tiff
:
:
Where as the German version looks like :
[MISC]
ERROR_LOADING_ERROR=Fehler waehrend dem laden der Fehlermeldungen. Datei 'errors.txt' defekt.
[2DGFX]
ERROR_LOADING_TIFF=Fehler waehrend des ladens des Tiff
:
:
To Create a CError object use one of the two constructors :
CError myError();
CError myError('errors.txt');
The only functions for CError are :
char *GetError(char *, int);
char *GetLastError();
char *ReloadErrorTable('filename');
The code to load a Tiff file with error messages could look like :
int result; CError myError('errors.txt'); // Load the error table CPicture myPicture(); // Create a Picture object CTiff *pTiff = new CTiff(); // create a tiff object on the heap // Try to load the picture 'test.tif' result = pTiff->Load2DGFX(myPicture, 'test.tif'); delete pTiff; // and remove the tiff object from the heap if (result != 0) { // if there was an error, get the error message // and generate MessageBox MesssageBox('Error', myError.GetError('[2DGFX]', result), MB_OK); exit(); } : :