Nicolas Besson - Microsoft Windows Embedded CE 6.0 Exam Preparation Kit

Здесь есть возможность читать онлайн «Nicolas Besson - Microsoft Windows Embedded CE 6.0 Exam Preparation Kit» весь текст электронной книги совершенно бесплатно (целиком полную версию без сокращений). В некоторых случаях можно слушать аудио, скачать через торрент в формате fb2 и присутствует краткое содержание. Город: Redmond, Год выпуска: 2008, Издательство: Microsoft, Жанр: Руководства, ОС и Сети, Программы, на английском языке. Описание произведения, (предисловие) а так же отзывы посетителей доступны на портале библиотеки ЛибКат.

Microsoft Windows Embedded CE 6.0 Exam Preparation Kit: краткое содержание, описание и аннотация

Предлагаем к чтению аннотацию, описание, краткое содержание или предисловие (зависит от того, что написал сам автор книги «Microsoft Windows Embedded CE 6.0 Exam Preparation Kit»). Если вы не нашли необходимую информацию о книге — напишите в комментариях, мы постараемся отыскать её.

Microsoft Windows Embedded CE 6.0 Exam Preparation Kit — читать онлайн бесплатно полную книгу (весь текст) целиком

Ниже представлен текст книги, разбитый по страницам. Система сохранения места последней прочитанной страницы, позволяет с удобством читать онлайн бесплатно книгу «Microsoft Windows Embedded CE 6.0 Exam Preparation Kit», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.

Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

Figure 6-3<\/strong>A sample .def file for a stream driver<\/p>

Sources File<\/p> <\/div>

Prior to building the newly created stream driver, you should also check the Sources file in the root folder of the DLL subproject to ensure that it includes all necessary files in the build process. As mentioned in Chapter 2, the Sources file configures the compiler and linker to build the desired binary files. Table 6-2 summarizes the most important Sources file directives for device drivers.<\/p>

Table 6-2 Important Sources file directives for device drivers<\/strong> <\/p>

Directive<\/th> Description<\/th> <\/tr>
WINCEOEM=1<\/td> Causes additional header files and import libraries from the %_WINCEROOT%\Public tree to be included to enable the driver to make platform-dependent function calls, such as KernelIoControl, InterruptInitialize, and InterruptDone.<\/td> <\/tr>
TARGETTYPE=DYNLINK<\/td> Instructs the Build tool to create a DLL.<\/td> <\/tr>
DEFFILE=< Driver Def File Name<\/em> >.def<\/td> References the module-definition file that defines the exported DLL functions.<\/td> <\/tr>
DLLENTRY=< DLL Main Entry Point<\/em> ><\/td> Specifies the function that is called when processes and threads attach and detach to and from the driver DLL (Process Attach, Process Detach, Thread Attach, and Thread Detach).<\/td> <\/tr> <\/table>

Opening and Closing a Stream Driver by Using the File API<\/p> <\/div>

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.<\/p>

// Open the driver, which results in a call to the SMP_Open function<\/code> <\/p>

hSampleDriver = CreateFile(L"SMP1:",<\/code> <\/p>

GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,<\/code> <\/p>

OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);<\/code> <\/p>

if (hSampleDriver == INVALID_HANDLE_VALUE) {<\/code> <\/p>

ERRORMSG(1,(TEXT("Unable to open the driver.\r\n"));<\/code> <\/p>

return FALSE;<\/code> <\/p>

}<\/code> <\/p>

// Access the driver and perform read,<\/code> <\/p>

// write, and seek operations as required.<\/code> <\/p>

// Close the driver<\/code> <\/p>

CloseHandle(hSampleDriver);<\/code> <\/p>

Dynamically Loading a Driver<\/p> <\/div>

As mentioned earlier in this lesson, an application can also communicate with a stream device driver after calling the ActivateDevice or ActivateDeviceEx function. ActivateDeviceEx offers more flexibility than ActivateDevice, yet both functions cause Device Manager to load the stream driver and call the driver's XXX_Init function. In fact, ActivateDevice calls ActivateDeviceEx. Note, however, that ActivateDeviceEx does not provide access to an already loaded driver. The primary purpose of the ActivateDeviceEx function is to read a driver-specific registry key specified in the function call to determine the DLL name, device prefix, index, and other values, add the relevant values to the active device list, and then load the device driver into the Device Manager process space. The function call returns a handle that the application can later use to unload the driver in a call to the DeactivateDevice function.<\/p>

ActivateDeviceEx replaces the older RegisterDevice function as a method to load a driver on demand, as illustrated in the following code sample:<\/p>

// Ask Device Manager to load the driver for which the definition<\/code> <\/p>

// is located at HKLM\Drivers\Sample in the registry.<\/code> <\/p>

hActiveDriver = ActivateDeviceEx(L"\\Drivers\\Sample", NULL, 0, NULL);<\/code> <\/p>

if (hActiveDriver == INVALID_HANDLE_VALUE) {<\/code> <\/p>

ERRORMSG(1, (L"Unable to load driver"));<\/code> <\/p>

return -1;<\/code> <\/p>

}<\/code> <\/p>

// Once the driver is lodaded, applications can open the driver<\/code> <\/p>

hDriver = CreateFile (L"SMP1:",<\/code> <\/p>

GENERIC_READ| GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,<\/code> <\/p>

OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);<\/code> <\/p>

if (hDriver == INVALID_HANDLE_VALUE) {<\/code> <\/p>

ERRORMSG(1, (TEXT("Unable to open Sample (SMP) driver")));<\/code> <\/p>

return 0; //Insert code that uses the driver here<\/code> <\/p>

}<\/code> <\/p>

// Close the driver when access is no longer needed<\/code> <\/p>

if (hDriver != INVALID_HANDLE_VALUE) {<\/code> <\/p>

bRet = CloseHandle(hDriver);<\/code> <\/p>

if (bRet == FALSE) {<\/code> <\/p>

ERRORMSG(1, (TEXT("Unable to close SMP driver")));<\/code> <\/p>

}<\/code> <\/p>

}<\/code> <\/p>

// Manually unload the driver from the system using Device Manager<\/code> <\/p>

if (hActiveDriver != INVALID_HANDLE_VALUE) {<\/code> <\/p>

bRet = DeactivateDevice(hActiveDriver);<\/code> <\/p>

if (bRet == FALSE) {<\/code> <\/p>

ERRORMSG(1, (TEXT("Unable to unload SMP driver ")));<\/code> <\/p>

}<\/code> <\/p>

}<\/code> <\/p>

NOTE<\/div>
Automatic vs. dynamic loading of drivers<\/div>

Calling ActivateDeviceEx to load a driver has the same result as loading the driver automatically during the boot process through parameters defined in the HKEY_LOCAL_MACHINE\Drivers\BuiltIn key. The BuiltIn registry key is covered in more detail in Lesson 3 later in this chapter.<\/p> <\/cite>

Lesson Summary<\/p> <\/div>

Stream drivers are Windows Embedded CE drivers that implement the stream interface API. The stream interface enables Device Manager to load and manage these drivers, and applications can use standard file system functions to access these drivers and perform I/O operations. To present a stream driver as a file resource accessible through a CreateFile call, the name of the stream driver must follow a special naming convention that distinguishes the device resource from ordinary files. Legacy names (such as COM1:) have a limitation of ten instances per driver because they include only a single-digit instance identification. If you must support more than ten driver instances on a target device, use a device name instead (such as \$device\COM1).<\/p>

Читать дальше
Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

Похожие книги на «Microsoft Windows Embedded CE 6.0 Exam Preparation Kit»

Представляем Вашему вниманию похожие книги на «Microsoft Windows Embedded CE 6.0 Exam Preparation Kit» списком для выбора. Мы отобрали схожую по названию и смыслу литературу в надежде предоставить читателям больше вариантов отыскать новые, интересные, ещё непрочитанные произведения.


Отзывы о книге «Microsoft Windows Embedded CE 6.0 Exam Preparation Kit»

Обсуждение, отзывы о книге «Microsoft Windows Embedded CE 6.0 Exam Preparation Kit» и просто собственные мнения читателей. Оставьте ваши комментарии, напишите, что Вы думаете о произведении, его смысле или главных героях. Укажите что конкретно понравилось, а что нет, и почему Вы так считаете.

x