In part one I showed you how to open a Library. But just the Library is not enough as we also need to open the Interface of the Library.

Amiga Editor - Open Libraries OPENINGThe statement “IIntuition = (struct IntuitionIFace *) IExec->GetInterface (IntuitionBase, “main”, 1, NULL);” will open the Interface of the Intuition Library. IExec->GetInterface will open the Interface of the Intuition Library. The (struct IntuitionIFace *) will make sure the value returned will be of the type struct IntuitionIFace. This is called a cast and if you have opened libraries on the classic Amiga you have encountered this before and are familiar with it. It might be somewhat technical to understand at first. With a cast we are forcing the system to make sure the returned value is of a value we need. See it as asking for Euros and to make sure you get Euros and not Dollars you clearly tell the person at the other end of the booth that you need it to be in Euros. That, telling the person, is what you can call the cast.

The part (IntuitionBase, “main”, 1, NULL); is trying to get the Interface of the (IntuitionBase) Intuition Library. Looking at ….“main”, 1, NULL); we can see that we are trying to get the main interface and the version number is 1. The last parameter (NULL) is a pointer to a tag list which we won’t discuss here. Just like with the Library we need to check if we managed to get the Interface. If we did IIntuition would not be zero (NULL) and we managed to get the Interface. If it is still zero (NULL) we failed to get the Interface. The “if (IIntuition != NULL)” statement will check this for us.

Of course we need to close everything we have opened.

Amiga Editor - Open Libraries CLOSINGThe IExec->DropInterface will close the Interface if it is open. The “struct Interface *” part is indeed a cast telling that the value of IIntuition is of the type struct Interface. When we tried to get the Interface we checked if it succeeded or not. If it would have failed our code would drop to this part printing that we cannot get the Interface. The same goes for the Library part. If it is open close it and if our previous check to see if we managed to open the Library resulted in failure our code would drop to this part printing that we are unable to open the Library.

Getting to understand the opening and closing of Libraries and Interfaces can be a bit of a hurdle at first. Besides talking about it here I also have some other articles in The Bucket Programming Corner that discuss Libraries and Interfaces with an example as well. Don’t worry as sooner or later you will understand the concept of Libraries and Interfaces.

That leaves us with ReAction classes. It’s the same concept as with the Libraries. You open it, check if you managed or failed and when you are done close them

Amiga Editor - Classes STRUCTSIn this example we are trying to open the Window Class. When we open the Window Class we need to store the value somewhere. For this we have the statement “struct ClassLibrary *WindowBase = NULL;”. And yes we indeed set it to zero (NULL) like we did with the Library so we can check if we succeeded in opening the Window Class. Besides opening the Window Class we will also have to get it’s Class pointer. And this also need to be stored somewhere for which we have the statement “Class *WindowClass;”. We will discuss the concept class pointer at a later stage. For now all we need to know is that besides the Class we also need to get the Class pointer.

Amiga Editor - Classes OpeningThe above statement will open the Window Class Library and the Class pointer in one time. The part “52” is the minimum version we want. We check just like with the Libraries if we managed to open the Window Class. The “&WindowClass” part will get the Class pointer. I could not find any info on this but I assume that if we managed to open the Window Class we automatically will get the Class pointer and do not need to check this as well.

Amiga Editor - Classes ClosingAll that is left is to close the Window Class Library. With it we also take care of the Class pointer. Just like with the Library example our code with jump to here if we failed to open the Window Class Library and prints that we are unable to do this. That’s it for this short tutorial in Libraries and Interfaces and ReAction classes.

Advertisements