874226@watt.usask.ca (Shawn Switenky) (01/29/91)
Hello All, I need help. I'm learnig both C and Amiga specific programming at the same time. I've been trying to get the following program working. All it does is create a window on a custom screen, and ten wiat for you to click on the close button. Simple, right? What it actally does is hang. It give me a requester then says: Software Failed Error number #80000004 It compiles and links without any errors or warnings. When I run it, it hangs. I'm using SAS C 5.10a under Workbench 2.02 and using the 2.0 version of includes. When I run CodeProbe on it, it hangs after the line: if (IntuitionBase == NULL) exit(1); and I have to reboot the machine. I believe I am not successful in opening up the intuition.library, and it could be because of the version number. I'm using old documentation ( V1.1 RKM's and Leemon's Inside Amiga Graphics ) and I beleve that the version number parameter format has changed. But I believe that a version number of 36 should work right? As you see, I am confused and frustrated. Can anyone spot my problem? Here is the code. #include "exec/types.h" #include "intuition/intuition.h" #include "stdlib.h" struct IntuitionBase *IntuitionBase; struct GfxBase *GfxBase; struct Screen *CustScr; struct Window *Wdw; struct ViewPort *WVP; #define WHITE 0xFFF #define RED 0xF00 #define GREEN 0x0f0 #define BLUE 0x00f #define CYAN 0x0ff #define PURPLE 0xf0f #define YELLOW 0xff0 #define BLACK 0x000 #define BGRP 0 #define WHTP 1 #define BLUP 2 #define REDP 3 #define GRNP 4 #define YELP 5 #define PURP 6 #define CYNP 7 static USHORT colormap [8] ={BLACK,WHITE,BLUE,RED,GREEN,YELLOW,PURPLE,CYAN}; struct TextAttr StdFont = { "topaz.font", TOPAZ_EIGHTY, FS_NORMAL, FPF_ROMFONT, }; struct NewScreen NewCustScr = { 0,0, /* Left Edge, Top Edge */ 320,200,3, /* Width, Depth, Height */ PURP,YELP, /* Detail Pen and Block Pen */ SPRITES, /* Special Display Modes */ CUSTOMSCREEN, /* Screen Type */ &StdFont, /* Pointer to Custom Font */ NULL, /* Pointer to Title Text */ NULL, /* Pointer to Screen Gadgets */ NULL, /* Pointer to Custom BitMap */ }; struct NewWindow NewWdw = { 0,0, /* Left Edge, Top Edge */ 320,200, /* Width, Height */ BLUP,WHTP, /* Block Pen, Detail Pen */ CLOSEWINDOW, /* IDCMP Flags */ SMART_REFRESH | ACTIVATE | BORDERLESS | WINDOWCLOSE, /* FLAGS */ NULL, /* Pointer to first gadget */ NULL, /* Pointer to Checkmark Image */ NULL, /* Title */ NULL, /* Pointer to Screen structure, dummy */ NULL, /* Pointer to Custom BitMap */ 0,0, /* Minimum Width, Minimum Height */ 0,0, /* Maximum Width, Height */ CUSTOMSCREEN, /* Type of screen it resides on */ }; void main(void) { /* Open the Intuition and Graphics Libraries, */ /* Get pointers to the routines */ IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library",36); if ( IntuitionBase == NULL ) exit(1); GfxBase = (struct GfxBase *) OpenLibrary("graphics.library",36); if ( GfxBase == NULL ) exit(1); if ( (NewWdw.Screen=CustScr=(struct Screen *)OpenScreen(&NewCustScr) ) ==NULL) exit(1); if ( (Wdw = (struct Window *)OpenWindow(&NewWdw))==NULL) exit(1); WVP = (struct ViewPort *)ViewPortAddress(Wdw); LoadRGB4(WVP,&colormap,8); Wait(1<<Wdw->UserPort->mp_SigBit); CloseWindow(Wdw); CloseScreen(CustScr); CloseLibrary(GfxBase); CloseLibrary(IntuitionBase); } Shawn Switenky 874226@watt.usask.ca
lkoop@pnet01.cts.com (Lamonte Koop) (01/29/91)
874226@watt.usask.ca (Shawn Switenky) writes: >Hello All, > I need help. I'm learnig both C and Amiga specific programming at >the same time. I've been trying to get the following program working. All >it does is create a window on a custom screen, and ten wiat for you to click >on the close button. Simple, right? > What it actally does is hang. It give me a requester then says: >Software Failed >Error number #80000004 > It compiles and links without any errors or warnings. When I run it, >it hangs. I'm using SAS C 5.10a under Workbench 2.02 and using the 2.0 >version of includes. > When I run CodeProbe on it, it hangs after the line: >if (IntuitionBase == NULL) exit(1); > and I have to reboot the machine. > > I believe I am not successful in opening up the intuition.library, and >it could be because of the version number. I'm using old documentation ( V1.1 Yes, your problem is in the opening of intuition.library. Read on: >#include "exec/types.h" >#include "intuition/intuition.h" >#include "stdlib.h" > >struct IntuitionBase *IntuitionBase; >struct GfxBase *GfxBase; > >struct Screen *CustScr; >struct Window *Wdw; >struct ViewPort *WVP; [some stuff deleted] > >void main(void) >{ > /* Open the Intuition and Graphics Libraries, */ > /* Get pointers to the routines */ > > IntuitionBase = (struct IntuitionBase *) > OpenLibrary("intuition.library",36); > if ( IntuitionBase == NULL ) exit(1); > > GfxBase = (struct GfxBase *) > OpenLibrary("graphics.library",36); > if ( GfxBase == NULL ) exit(1); In order not to limit yourself to the version number (unless it is important), use 0L for the version number. This is an "I don't care" number saying "Just open intuition.library, whatever the version". Remember, the version numbers are long values, hence 0L. Also, it's common to shorten a statement such as yours with the "not" operator ('!'), such as: if(!(IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library",0L))) exit(1); This is valid as any zero value is considered "false" in C. Also, IntuitionBase and GfxBase should be declared as extern such: extern struct IntuitionBase *IntuitionBase; extern struct GfxBase *GfxBase; as they are variables pulled in with the startup code. Now, if you are not using the standard startup code, then your declaration is perfectly fine. LaMonte Koop Internet: lkoop@pnet01.cts.com ARPA: crash!pnet01!lkoop@nosc.mil UUCP: {hplabs!hp-sdd ucsd nosc}!crash!pnet01!lkoop A scientist is one who finds interest in the kinetic energy of Jell-O moving at ridiculous velocities...an engineer is one who can find a real-life application for such silliness.