Книга: Microsoft Windows Embedded CE 6.0 Exam Preparation Kit

Opening and Closing a Stream Driver by Using the File API

Opening and Closing a Stream Driver by Using the File API

To access a stream driver, an application can use the CreateFile function and specify the desired device name. The following example illustrates how to open a driver called SMP1: for reading and writing. It is important to note, however, that Device Manager must already have loaded the driver, such as during the boot process. Lesson 3 later in this chapter provides detailed information about configuring and loading device drivers.

// Open the driver, which results in a call to the SMP_Open function
hSampleDriver = CreateFile(L"SMP1:",
 GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hSampleDriver == INVALID_HANDLE_VALUE) {
 ERRORMSG(1,(TEXT("Unable to open the driver.rn"));
 return FALSE;
}
// Access the driver and perform read,
// write, and seek operations as required.
// Close the driver
CloseHandle(hSampleDriver);

Оглавление книги


Генерация: 1.098. Запросов К БД/Cache: 3 / 1
поделиться
Вверх Вниз