I already ran into my first problem. Well not so much a problem but more of a query. It has to do with checking if something was successfully opened. We do it when we open a library and also the interface of it. You might still remember it from The Bucket Programming Corner but for reference I will place the source code below.

(Note: the code is not complete since we use a if statement to make a check but we need to use the else statement to complement it. Of course in the example code of the article it is complete.)

struct Library *IntuitionBase = NULL;

struct IntuitionIFace *IIntuition = NULL;

/* Opening the Intuition Library */
IntuitionBase = IExec->OpenLibrary(“intuition.library”, 50L);

/* Did we manage to open the Intuition Library? */
if (IntuitionBase != NULL)
{

printf (“We opened the Intuition Library!!\n”);

/* Open the Intuition Interface */
IIntuition = (struct IntuitionIFace *) IExec->GetInterface (IntuitionBase, “main”, 1, NULL);

/* Did we get the Intuition Interface? */
if (IIntuition != NULL)
{

printf (“We did get the Intuition Interface!!\n”);

The most important thing you need to do is to make sure you set both *IntuitionBase and *IIntuition to zero (NULL). If we set it to NULL and we open the library and get the interface the value of both *IntuitionBase and *IIntuition should be NOT (hence the !=NULL) zero. If they are it would mean that we failed to open the library or did not get the interface. If we do not set both *IntuitionBase and IIntuition to NULL we cannot do a proper check. Even worse we could and almost surely would crash the system.

All of the above bring me to the issue I ran into. If you read Trixie’s article over at OS4Coding.net you know that instead of using OpenLibrary() to open ReAction Classes we should use OpenClass() to open the ReAction Classes. Besides returning the class library base (which we store in WindowBase) it will also return something called the class pointer. Have a look at the below code.

struct ClassLibrary *WindowBase = NULL;

Class *WindowClass;

WindowBase = IIntuition->OpenClass(“window.class”, 50, &WindowClass);

if (WindowBase != NULL)
{

printf (“We opened the Window Class Library!!\n”);

}
else

printf (“We failed opening the Window Class Library!!\n”);

As you can see we open the Window class and with it the class pointer. My question about this is that when we check if we opened the Window class do we also need to check if we got the pointer and if so how? Or can we assume that if we succeed in opening the Window class we also have successfully got the class pointer? I assume the last is the case. If we successfully opened the Window class we will also have successfully got the class pointer. Let’s say the system is not capable of storing the class pointer in &WindowClass for whatever reason it will mark it as failing to open the Window class and the WindowBase value would be NULL. I am not 100% sure about this but for now I will assume this is the case. I am still trying to figure this out by speaking to some OS4 programmers and once I got the final answer I will let you all know.

Advertisements