3 Name: example_hookuse.c
4 Versionstring: $VER: example_hookuse.c 1.0 (06.10.2004)
7 Description: shows how the SDI_hook.h header include are used
9 1.0 06.10.04 : initial version showing how the SDI_hook.h header have to be
10 used if one wants to keep the sources platform independent
11 throughout all common AmigaOS compatible platforms like OS3,
15 Please note that this example is just for educational purposes and wasn't
16 checked for complete correctness. However, it should compile and probably also
17 work as expected. But please note that its purpose is to show how the hook
18 macros make it very easy to deal with hooks and also keep the sources simple
19 and platform independent through OS3, OS4 and MorphOS.
21 Feel free to comment and submit any suggestions directly to
22 Jens.Langner@light-speed.de
26 #include <proto/exec.h>
27 #include <proto/utility.h>
35 /******************************************************************************/
36 /* Own hook definitions */
37 /******************************************************************************/
39 // The following hook is just an example hook where we use the object
40 // for printing out some minor text. Do you see how easy it is to use hooks and
41 // how great it is to use SDI_hook.h to automatically keep your sources compatible
42 // to all common AmigaOS platforms?
43 HOOKPROTONHNP(HelloFunc
, LONG
, char *txt
)
45 printf("'%s' which returns ", txt
);
49 MakeStaticHook(HelloHook
, HelloFunc
);
51 /******************************************************************************/
52 /* The main entry point to just illustrate how the hook is called */
53 /******************************************************************************/
55 struct Library
*UtilityBase
;
56 #if defined(__amigaos4__)
57 struct UtilityIFace
*IUtility
;
58 #define GETINTERFACE(iface, base) (iface = (APTR)GetInterface((struct Library *)(base), "main", 1L, NULL))
59 #define DROPINTERFACE(iface) { DropInterface((APTR)(iface)); iface = NULL; }
61 #define GETINTERFACE(iface, base) TRUE
62 #define DROPINTERFACE(iface)
69 if((UtilityBase
= OpenLibrary("utility.library", 37)))
71 if(GETINTERFACE(IUtility
, UtilityBase
))
73 printf("Hello! I am a ");
75 ret
= CallHook(&HelloHook
, "portable Hook");
79 DROPINTERFACE(IUtility
);
82 CloseLibrary(UtilityBase
);