OpenDriverYou can use the
OpenDriverfunction to open a closed device driver or to determine the driver reference number of an open device driver.
pascal OSErr OpenDriver(ConstStr255Param name, short *drvrRefNum);
- The name of the driver to open. A driver name consists of a period (.) followed by any sequence of 1 to 255 printing characters. The Device Manager ignores case (but not diacritical marks) when comparing names.
- The driver reference number of the opened driver.
OpenDriverfunction opens the device driver specified by the
nameparameter and returns its driver reference number in the
drvrRefNumparameter. To avoid replacing an open driver, the Device Manager searches the drivers that are already installed in the unit table before searching driver resources. If the specified driver is already open, this function simply returns the driver reference number.
If the driver is not already open, the Device Manager calls the
GetNamedResourcefunction using the specified name and the resource type
'DRVR'. If the resource is found, the resource ID defines the unit number of the driver, which determines the location in the unit table where the Device Manager stores the handle to the driver's device control entry (DCE).
After loading the driver resource into memory, the Device Manager creates a DCE for the driver, copies the flags from the driver header to the
dCtlFlagsfield, and places the driver reference number in the
OpenDriverfunction is a high-level version of the low-level
PBOpenfunction. Use the
PBOpenfunction when you need to specify read/write permission for the driver. The next section describes the
SPECIAL CONSIDERATIONSBecause another driver might already be installed in the unit table at the location determined by the driver's resource ID, you should first search for an unused location in the unit table and renumber the driver resource accordingly before calling this function. See Listing 1-1 on page 1-18 for an example.
OpenDriverfunction may move memory; you should not call it at interrupt time.
noErr 0 No error badUnitErr -21 Driver reference number does not match unit table unitEmptyErr -22 Driver reference number specifies a
nilhandle in unit table
openErr -23 Requested read/write permission does not match driver's open permission dInstErr -26 Driver resource not found
SEE ALSOFor information about the low-level functions for opening devices, see the next section, which describes the
PBOpenfunction, and the description of the
OpenSlotfunction on page 1-63. For an example of how to open a device driver using the
OpenDriverfunction, see Listing 1-1 on page 1-18.