Platform SDK: Hardware

Device Handles

When you call the DeviceIoControl function, you must specify a handle that identifies the device to access. You can use the CreateFile function to get a device handle.

The CreateFile call must specify either the name of a device or the name of the driver associated with a device. To specify a device name, the lpszname parameter of CreateFile specifies a string with the format

\\.\DeviceName 
 

The types of devices that you can open and the method that you must use to specify them in the CreateFile function depend on the platform on which your application is running.

You should specify the FILE_SHARE_READ and FILE_SHARE_WRITE access flags when calling CreateFile to open a handle to a device driver. However, when you open a communications resource, such as a serial port, you must specify exclusive access. Use the other CreateFile parameters as follows when opening a device handle: