Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: Devices /
Chapter 1 - Device Manager / Device Manager Reference
Device Manager Functions / Opening and Closing Device Drivers


OpenDriver

You can use the OpenDriver function 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); 
name
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.
drvrRefNum
The driver reference number of the opened driver.
DESCRIPTION
The OpenDriver function opens the device driver specified by the name parameter and returns its driver reference number in the drvrRefNum parameter. 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 GetNamedResource function 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 dCtlFlags field, and places the driver reference number in the dCtlRefNum field.

The OpenDriver function is a high-level version of the low-level PBOpen function. Use the PBOpen function when you need to specify read/write permission for the driver. The next section describes the PBOpen function.

SPECIAL CONSIDERATIONS
Because 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.

The OpenDriver function may move memory; you should not call it at interrupt time.

RESULT CODES
noErr0No error
badUnitErr-21Driver reference number does not match unit table
unitEmptyErr-22Driver reference number specifies a nil handle in unit table
openErr-23Requested read/write permission does not match driver's open permission
dInstErr-26Driver resource not found
SEE ALSO
For information about the low-level functions for opening devices, see the next section, which describes the PBOpen function, and the description of the OpenSlot function on page 1-63. For an example of how to open a device driver using the OpenDriver function, see Listing 1-1 on page 1-18.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
3 JUL 1996