RegisterBGIdriver (function) (Graph unit)


 RegisterBGIdriver (function)     (Graph unit)

Passes the graphics system a pointer to a device driver that has been linked into an application program.


 function RegisterBGIdriver(driver: pointer): Integer;


Real, Protected


The driver must be registered before the call to InitGraph.

If an error occurs, the return value is less than 0;otherwise, the internal driver number is returned.

This routine enables a user to load a driver file and "register" the driver by passing its memory location to RegisterBGIdriver. When that driver is used by InitGraph, the registered driver will be used (instead of being loaded from disk by the Graph unit). A user-registered driver can be loaded from disk onto the heap, or converted to an .OBJ file (using BINOBJ.EXE) and linked into the .EXE.

Returns grInvalidDriver if the driver header is not recognized.

The following program loads the CGA driver onto the heap, registers it with the graphics system, and calls InitGraph:

 program LoadDriv;
 uses Graph;
   Driver, Mode: Integer;
   DriverF: file;
   DriverP: Pointer;
   { Open driver file, read into memory, register it }
   Assign(DriverF, 'CGA.BGI');
   Reset(DriverF, 1);
   GetMem(DriverP, FileSize(DriverF));
   BlockRead(DriverF, DriverP^, FileSize(DriverF));
   if RegisterBGIdriver(DriverP) < 0 then
     Writeln('Error registering driver: ',
   { Init graphics }
   Driver := CGA;
   Mode := CGAHi;
   InitGraph(Driver, Mode, '');
   if GraphResult < 0 then
   OutText('Driver loaded by user program');

The program begins by loading the CGA driver file from disk and registering it with the Graph unit. Then a call is made to InitGraph to initialize the graphics system. You might wish to incorporate one or more driver files directly into your .EXE file. In this way, the graphics drivers that your program needs will be built-in and only the .EXE will be needed to run. The process for incorporating a driver file into your .EXE is straight forward:

   - Run BINOBJ on the driver file(s).
   - Link the resulting .OBJ file(s) into your program.
   - Register the linked-in driver file(s) before calling InitGraph

See Also

Sample Code

Тэги: RegisterBGIdriver
| G+
Код для вставки: :: :: :: ::
Поделиться: // //