Installs a vendor-added device driver to the BGI device driver table
int far installuserdriver(char far *name, int huge (*detect)(void));
With installuserdriver, you can add a vendor-added device driver to
the BGI internal table.
Argument│ What It Is/Does
name │ Name of the new device driver file (filename.BGI)
detect │ Points to an optional autodetect function that can accompany the
│ new driver. This autodetect function takes no parameters and
│ returns an integer value.
You can install up to 10 drivers at one time.
There are two ways to use the vendor-supplied driver:
1) passing the driver number directly to
2) linking in an autodetect function.
Passing driver number directly to initgraph
Assume you have a new video card called the Spiffy Graphics Array
(SpGA) and that the SpGA manufacturer provided you with a BGI device
The easiest way to use this driver is to install it by calling
installuserdriver and then passing the return value (the assigned
driver number) directly to initgraph.
Linking in an autodetect function
The more general way to use this hypothetical SpGA driver is to link
in an autodetect function that will be called by initgraph as part of
its hardware-detection logic. (Presumably, the manufacturer of the
SpGA gave you this autodetect function).
When you install the driver (by calling installuserdriver), you pass
the address of this autodetect function, along with the device
driver's file name.
After you install the device driver's file name and the SpGA
autodetect function, call initgraph and let it go through its normal
Before initgraph calls its own built-in autodetection function
(detectgraph), it first calls the SpGA autodetect function.
■ If the SpGA autodetect function doesn't find the SpGA hardware, it
returns a value of -11 (grError), and initgraph proceeds with its
normal hardware detection logic.
(This can include calling any other vendor-supplied autodetection
functions in the order in which they were "installed").
■ If, however, the autodetect function determines that an SpGA is
present, it returns a non-negative mode number.
1) locates and loads SPGA.BGI
2) puts the hardware into the default
graphics mode recommended by the
3) returns control to your program.
Returns the driver number you pass to initgraph to manually select the
newly installed driver.
╔ DOS Đ UNIX Đ ANSI C Đ C++ Only ╗
║ Yes │ │ │ ║
/* function prototypes */
int huge detectEGA(void);
int gdriver, gmode;
/* install a user written device driver */
gdriver = installuserdriver("EGA", detectEGA);
/* must force use of detection routine */
gdriver = DETECT;
/* check for any installation errors */
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "");
/* check for any initialization errors */
/* draw a line */
line(0, 0, getmaxx(), getmaxy());
/* clean up */
/* detects EGA or VGA cards */
int huge detectEGA(void)
int driver, mode, sugmode = 0;
if ((driver == EGA) || (driver == VGA))
/* return suggested video mode number */
/* return an error code */
/* check for and report any graphics errors */
/* read result of last graphics operation */
errorcode = graphresult();
if (errorcode != grOk)
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");