graphresult


Syntax
#include <graphics.h>
int graphresult(void);
Description
graphresult returns the error code for the last graphics operation that reported an error and resets the error level to grOk.

The following table lists the error codes returned by graphresult. The enumerated type graph_errors defines the errors in this table. graph_errors is declared in graphics.h.

code    constant Corresponding error message string
0 grOk No error
-1 grNoInitGraph (BGI) graphics not installed (use initgraph)
-2 grNotDetected Graphics hardware not detected
-3 grFileNotFound Device driver file not found
-4 grInvalidDriver Invalid device driver file
-5 grNoLoadMem Not enough memory to load driver
-6 grNoScanMem Out of memory in scan fill
-7 grNoFloodMem Out of memory in flood fill
-8 grFontNotFound     Font file not found
-9 grNoFontMem Not enough memory to load font
-10 grInvalidMode Invalid graphics mode for selected driver
-11 grError Graphics error
-12 grIOerror Graphics I/O error
-13 grInvalidFont Invalid font file
-14 grInvalidFontNum Invalid font number
-15 grInvalidDeviceNum Invalid device number
-18 grInvalidVersion Invalid version number
Note: The variable maintained by graphresult is reset to 0 after graphresult has been called. Therefore, you should store the value of graphresult into a temporary variable and then test it.

Return Value
graphresult returns the current graphics error number, an integer in the range -15 to 0; grapherrormsg returns a pointer to a string associated with the value returned by graphresult.

See also
detectgraph
drawpoly
fillpoly
floodfill
grapherrormsg
initgraph
pieslice
registerbgidriver
registerbgifont
setallpalette
setcolor
setfillstyle
setgraphmode
setlinestyle
setpalette
settextjustify
settextstyle
setusercharsize
setviewport
setvisualpage

Example
/* graphresult example */ 

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>

int main(void)
{
   /* request autodetection */
   int gdriver = DETECT, gmode, errorcode;

   /* initialize graphics and local variables */
   initgraph(&gdriver, &gmode, "");

   /* read result of initialization */
   errorcode = graphresult();

   if (errorcode != grOk) {  /* an error occurred */
      printf("Graphics error: %s\n", grapherrormsg(errorcode));
      printf("Press any key to halt:");

      getch();
      exit(1);               /* terminate with an error code */
   }

   /* draw a line */
   line(0, 0, getmaxx(), getmaxy());

   /* clean up */
   getch();
   closegraph();
   return 0;
}

Back to index