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

? Access the Driver from an Application

? Access the Driver from an Application

1. Create a new WCE Console Application subproject as part of your OS design by using the Windows Embedded CE Subproject Wizard. Select WCE Console Application and the template A Simple Windows Embedded CE Console Application.

2. Modify the subproject image settings to exclude the subproject from the image by right clicking the OS design name in the solution view and selecting Properties.

3. Include <windows.h> and <winioctl.h>

4. Add code to the application to open an instance of the driver by using CreateFile. For the second CreateFile parameter (dwDesiredAccess), pass in GENERIC_READ | GENERIC_WRITE. For the fifth parameter (dwCreationDisposition), pass in OPEN_EXISTING. If you open the driver with the $device naming convention, be sure to escape the slashes and not include the colon at the end of the filename.

HANDLE hDrv = CreateFile(L"$deviceSTR1",
 GENERIC_READ|GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);

5. Copy the IOCTL header file (String_ioctl.h) from the string driver folder to the new application's folder and include it in the source code file.

6. Declare an instance of a PARMS_STRING structure defined in String_iocontrol.h, included along with the rest of the sample string driver, to enable applications to store a string in the driver using the following code:

PARMS_STRING stringToStore;
wcscpy_s(stringToStore.szString, STR_MAX_STRING_LENGTH,
 L"Hello, driver!");

7. Use a DeviceIoControl call with an I/O control code of IOCTL_STRING_SET to store this string in the driver.

8. Run the application by building it and selecting Run Programs from the Target menu.

9. The Debug window should show the message Stored String "Hello, driver!" Successfully when you run the application, as shown in Figure 6-12.


Figure 6-12 A debug message from the string driver

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


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