GRAphical Programming for Eiffel index contents

Appendix E. How to Access Windows API Directly

GRAPE encapsulates most of the Microsoft Windows API. From other side all classes used in GRAPE now are portable to the other graphical platforms (e.g. MOTIF). Nevertheless in some particular cases you can access the Microsoft Windows API directly by using the interface with C language (the "external C" Eiffel construction (see [Mey92] chapter 24)).

In this appendix we explain how to do it. For example we show how to implement the simple beep feature. This feature produces a simple sound. In GRAPE this feature is defined in class WINDOW.

feature {ANY}
   beep ( code: INTEGER ) is 
     do
       perform_system_beep ( code );
     end
feature {NONE} -- hide beep implementation 
   perform_system_beep ( code: INTEGER ) is

     external "C"
     alias "perform_system_beep"

     end 

Next you should create a C-implementation for procedure perform_ system_beep. It might look something like as follows:

#include <windows.h>
#include "eiffel.h"

//----------------------------------------------------------------
void perform_system_beep ( INTEGER beep_code )
{
   UINT system_code;
   switch ( beep_code ) {
     case 0: system_code = (UINT)-1; break;
     case 1: system_code = MB_ICONASTERISK; break;
     case 2: system_code = MB_ICONEXCLAMATION; break;
     case 3: system_code = MB_ICONHAND; break;
     case 4: system_code = MB_ICONQUESTION; break;
     case 5: system_code = MB_OK; break;
     default: system_code = (UINT)-1; break; 
   }

   MessageBeep ( system_code );
}

You should compile this C code and make a library file from it. After this you should specify the library name in the Eiffel/S EIF2BIN file (into the linker statement) or add it to your makefile to link the C-library with your project. That's all.


© Object Tools -- info@object-tools.com -- December 1999