return TRUE;

}

DWORD SMP_Init(LPCTSTR pContext, LPCVOID lpvBusContext) {

 // Implement device context initialization code here.

 return 0x1;

}

BOOL SMP_Deinit(DWORD hDeviceContext) {

 // Implement code to close the device context here.

 return TRUE;

}

DWORD SMP_Open(DWORD hDeviceContext, DWORD AccessCode, DWORD ShareMode) {

 // Implement open context initialization code here.

 return 0x2;

}

BOOL SMP_Close(DWORD hOpenContext) {

 // Implement code to close the open context here.

 return TRUE;

}

DWORD SMP_Write(DWORD hOpenContext, LPCVOID pBuffer, DWORD Count) {

 // Implement the code to write to the stream device here.

 return Count;

}

DWORD SMP_Read(DWORD hOpenContext, LPVOID pBuffer, DWORD Count) {

 // Implement the code to read from the stream device here.

 return Count;

}

BOOL SMP_IOControl(DWORD hOpenContext, DWORD dwCode,

 PBYTE pBufIn, DWORD dwLenIn, PBYTE pBufOut,

 DWORD dwLenOut, PDWORD pdwActualOut) {

 // Implement code to handle advanced driver actions here.

 return TRUE;

}

void SMP_PowerUp(DWORD hDeviceContext) {

 // Implement power management code here or use IO Control.

 return;

}

void SMP_PowerDown(DWORD hDeviceContext) {

 // Implement power management code here or use IO Control.

 return;

}

Exporting Stream Functions

Making the stream functions in the driver DLL accessible to external applications requires the linker to export the functions during the build process. C++ provides several options to accomplish this, yet for driver DLLs compatible with Device

Manager, you must export the functions by defining them in the .def file of the DLL subproject. The linker uses the .def file to determine which functions to export and how to do so. For a standard stream driver, you must export the stream interface functions using the prefix that you specify in the driver's source code and registry settings. Figure 6-3 shows a sample .def file for the stream interface skeleton listed in the previous section.

Figure 6-3 A sample .def file for a stream driver

Sources File

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.

Table 6-2 Important Sources file directives for device drivers

Directive Description
WINCEOEM=1 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.
TARGETTYPE=DYNLINK Instructs the Build tool to create a DLL.
DEFFILE=<Driver Def File Name>.def References the module-definition file that defines the exported DLL functions.
DLLENTRY=<DLL Main Entry Point> 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).
Добавить отзыв
ВСЕ ОТЗЫВЫ О КНИГЕ В ИЗБРАННОЕ

0

Вы можете отметить интересные вам фрагменты текста, которые будут доступны по уникальной ссылке в адресной строке браузера.

Отметить Добавить цитату