I was always a fan of opening and closing my libraries myself. You could have them automatically opened and closed and save you the time of writing the code for it. I did sometimes switch to use the auto open and close function so I could skip writing code for it. When you have to open and close a lot of libraries this certainly save you a lot of time. Not to mention the check part if you actually managed to open them. I was about to switch to this automatically opening if libraries when I came across some new info regarding ReAction. Since ReAction classes are implemented as system libraries we use the OpenLibrary function to open them. With the release of OS4.x a new Intuition function called OpenClass has been introduced which will open ReAction classes. If we make use of the auto open function we will also open ReAction classes. To avoid problems we better switch to opening and closing everything ourself. Besides following the proper way of opening our ReAction classes we also have full control on what is happening with our code.
Let’s talk a bit about opening Libraries and of course closing them. And not to forget opening and closing ReAction classes. In this example we are going to open the Intuition Library. If you programmed in C on the classic Amiga and also worked with libraries you will notice something new when it comes to OS4.x. Besides opening the Library we also need to open it’s Interface. The Interface can be seen as a front end for the Library. Let’s say we want to ask the Library to do a certain task. Instead of asking it directly we will ask it’s Interface to talk for us with the Library. The reason why this Interface was added would be to technical and complicated (at this moment) to discuss but one of the reason has to do with compatibility of classic software.
First up we need to declare two pointer structures for our Library and it’s Interface. When we open both of them we need to store the values we get back and for this we have the above two statements. It is very important we set the value to zero (NULL). If we don’t they might point to a random address in memory which might cause the whole system to crash.
Next up we need to open the Library and also the Interface. With the statement “IntuitionBase = IExec->OpenLibrary(“intuition.library”, 50L);” we are trying to open the Intuition Library. Important to know is that with the Amiga OS there is always one Library open from the moment the system is up and running and that is the Exec Library. You might have guessed it already that the “IExec->” function is part of the Interface of the Exec Library. As explained before the Interface of the Exec Library is talking to the Exec Library for us and in this case it is asking to open the Intuition Library for us. The “50L” part is the minimum version we want to open. The value that we get back when trying to open it will be stored in IntuitionBase. We will have to check if we managed to open it. For this we will check the value that is stored in IntuitionBase. Remember we set it to zero (NULL)? So if we check that the value is not zero (NULL) we managed to open it. If it still has the value zero (NULL) we failed to open it.
I will divide this article in two parts. In the next and last part I will discuss opening the Interface of a Library as well as closing it including the Library and also discuss ReAction classes.