Programming AmigaOS in C

1. Magic User Interface (MUI)

MUI is a third party user interface replacement for AmigaOS. MUI allows programmers to create user interfaces much faster and easier than Intuition, Gadtools or Reaction and it is much easier to customize using the MUI Preferences. MUI works with AmigaOS 3 or later. For more information about MUI, visit the SASG web site. To use MUI you need to install the User Libraries and the Development kit from Aminet or MUI 4 from MUIDev.

2. Opening the MUI Library

To access shared libraries, you need to open them first before you can use the functions provided. This is done using the OpenLibrary() function which is an exec.library function.
When a library is opened, it will return a pointer to a Library type structure call MUIMasterBase.

Example, Opening the MUI Library

/* Include appropiate headers*/
#include <libraries/mui.h>
#include <proto/muimaster.h>

/* First declare a pointer to the MuiMaster structure */
struct MUIMasterBase *MUIMasterBase;

/* Now open the library for Intuition */
MUIMasterBase = (struct MUIMasterBase *)OpenLibrary("muimaster.library",20);

Note, that the result of OpenLibrary has been cast to type of MUIMasterBase, as by default, it will return a structure of type Library. You would normally test to see if that library is opened before trying to use of the functions and exit gracefully.
e.g.

if (MUIMasterBase) {
  /* some code here */
}
else {
   printf("Failed to open Mui Master library.\n");
   exit(5);
}

For AmigaOS 4, Opening a library is slightly different, instead of using a specific Library base structure, they all use the Library structure and to open a library use IExec->OpenLibrary() function instead, for example:

struct Library *MUIMasterBase;
MUIMasterBase = IExec->OpenLibrary("muimaster.library", 0L);

If you wish to compile your code for OS 3.x and OS 4.0 then use the #ifdef, #else and #endif feature.

e.g.

#ifdef OS3x
   MUIMasterBase = (struct MUIMasterBase *)OpenLibrary("muimaster.library", 39);
#else
   MUIMasterBase = IExec->OpenLibrary("muimaster.library", 50);
#endif 

3. Closing the MUI Library

To close a library, use the CloseLibrary() function and provide the pointer to the Library or Base structure which was returned in the OpenLibrary(). It is normal practice to test that the library was opened before trying to close it.
For example,

#ifdef OS3x
if
(MUIMasterBase) CloseLibrary( (struct MUIMasterBase *)MUIMasterBase); #else if (MUIMasterBase) IExec->CloseLibrary( (struct MUIMasterBase *)MUIMasterBase);
#endif

Next Page