Borland C++ reference

installuserdriver

raw OCR

Installs a vendor-added device driver to the BGI device driver table.

Defined in header <graphics.h>

Syntax

#include <graphics.h>
int far installuserdriver(char    far *name, int huge   {*detect){void));

Portability

DOSUNIXWindowsANSI CC++ only
■

Remarks

installuserdriver allows you to add a vendor-added device driver to the BGI internal table. The name parameter is the name of the new device driver file (.BGI), and the detect parameter is a pointer to an optional autodetect function that can accompany the new driver. This autodetect function takes no parameters and returns an integer value.

There are two ways to use this vendor-supplied driver. Let's assume you have a new video card called the Spiffy Graphics Array (SGA) and that the SGA manufacturer provided you with a BGI device driver (SGA.BGI). 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.

The other, more general way to use this driver is to link in an autodetect function that will be called by initgrapti as part of its hardware-detection logic (presumably, the manufacturer of the SGA gave you this autodetect function). When you install the driver (by calling installuserdriver), you pass the address of this function, along with the device driver's file name.

After you install the device driver file name and the SGA autodetect function, call initgraph and let it go through its normal autodetection process. Before initgraph calls its built-in autodetection function (detectgraph), it first calls the SGA autodetect function. If the SGA autodetect function doesn't find the SGA hardware, it returns a value of -11 (grError), and initgraph proceeds with its normal hardware detection logic (which 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 SGA is present, it returns a non-negative mode number; then initgraph locates and loads SGA.BGI, puts

the hardware into the default graphics mode recommendedby the

autodetect function, and finally returns control to your program.

You can install up to ten drivers at one time.

Return value

The value returned by instaliuserdriver is the driver number parameter you would pass to initgraph in order to select the newly installed driver manually.

See also

Example

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

/* function prototypes */
int huge detectEGA(void);
void checkerrors (void);
int main (void)
{
   int gdriver, graode;
   /* install a user written device driver  */
   gdriver = instaliuserdriver ("EGA", detectEGA);

   /* must force use of detection routine  */
   gdriver = DETECT;
   /* check for any installation errors  */
   checkerrors ();
   /* initialize graphics and local variables  */
   initgraph (&gdriver, &gmode, "");

   /* check for any initialization errors  */
   checkerrors ();

   /* draw a line */
   line(0, 0, getmaxxO,  getmaxyO);
   /* clean up */
   getchO ;
   closegraphO ;
   return
}
/* detects EGA or VGA cards  */
int huge detectEGA(void)
{
   int driver, mode, sugmode = 0;
   detectgraph(&driver, &mode) ;
   if { (driver == EGA) I I (driver == VGA))
      return sugmode;      /* return suggested video  mode number */
   else
      return grError;      /* return an error  code */
}
/* check for and report any graphics errors  */
void checkerrors(void)
{
   int errorcode;

   /* read result of last graphics operation  */
   errorcode = graphresult ();
   if (errorcode  != grOk) {
      printf ("Graphics error: %s\n", grapherrormsg(errorcode));
      printf ("Press any key to halt:");
      getchO ;
      exit(l);
   }

Differences from modern implementations

Nothing recorded yet.

Modern references

These are search links, not yet checked by hand.