Windows CE Simple Stream Driver
StreamTestDrv.cpp:
#include "stdafx.h"
#include "StreamTestDrv.h"
#include <WinBase.h>
#include <devload.h>
#define SIZE_DRV 100
BOOL APIENTRY DllMain( HANDLE hModule,DWORD ul_reason_for_call,
LPVOID lpReserved)
{
switch(ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
RETAILMSG(1, (TEXT("DLLMAIN: Process Attach\n")));
break;
case DLL_THREAD_ATTACH:
RETAILMSG(TRUE,(TEXT("DLLMAIN: Thread ATTACH \n")));
break;
case DLL_THREAD_DETACH:
RETAILMSG(TRUE,(TEXT(" DLLMAIN: Thread DETACH \n")));
break;
case DLL_PROCESS_DETACH:
RETAILMSG(1, (TEXT("DLLMAIN: Process Detach\n")));
break;
default:
RETAILMSG(1, (TEXT("DLLMAIN: Default\n")));
break;
}
return TRUE;
}
// This is an example of an exported variable
StreamTestDrv_API int nStreamTestDrv=0;
// This is an example of an exported function.
StreamTestDrv_API int fnStreamTestDrv(void)
{
return 42;
}
// This is the constructor of a class that has been exported.
// see StreamTestDrv.h for the class definition
CStreamTestDrv::CStreamTestDrv()
{
return;
}
BOOL DRV_Deinit(DWORD hdeviceContext)
{
RETAILMSG(TRUE, (TEXT("DRV Driver: DD_Deinit\n")));
return TRUE;
}
DWORD DRV_Init(LPCTSTR pContext, LPCVOID lpcContext)
{
RETAILMSG(TRUE, (TEXT("DRV Driver:DD_Init:%s\n"), pContext));
return 0x01;
}
DWORD DRV_Open(DWORD hDeviceContext, DWORD Accesscode, DWORD ShareMode)
{
RETAILMSG(TRUE, (TEXT("DRV Driver:Open\n")));
return ((DWORD) GetCurrentProcess());
}
BOOL DRV_Close(DWORD hDeviceContext)
{
RETAILMSG(TRUE, (TEXT("DRV Driver:Close\n")));
return TRUE;
}
DWORD DRV_Write(DWORD hOpenContext, LPCVOID buffer, DWORD count)
{
RETAILMSG(TRUE, (TEXT("DRV Driver:Write:%s \n"),buffer));
return count;
}
DWORD DRV_Read(DWORD hOpenContext, LPVOID buffer, DWORD count)
{
RETAILMSG(TRUE, (TEXT("DRV Driver:Read\n")));
return count;
}
DWORD DRV_Seek(DWORD hOpenContext, LONG position, DWORD type)
{
RETAILMSG(TRUE, (TEXT("DRV Driver:Seek\n")));
return 0;
}
BOOL DRV_IOCONTROL(DWORD hOpenContext, DWORD dword, PBYTE pBufIn,
DWORD dWLenIn, PBYTE pBufOut, DWORD dWLenOut,
PDWORD pdwordactual)
{
RETAILMSG(TRUE, (TEXT("DRV Driver:IOCONTROL\n")));
return TRUE;
}
void DRV_PowerUp(DWORD hOpenContext)
{
RETAILMSG(TRUE, (TEXT("DRV Driver:PowerUp\n")));
return;
}
void DRV_PowerDown(DWORD hOpenContext)
{
RETAILMSG(TRUE, (TEXT("DRV Driver:PowerDown\n")));
return;
}
StreamTestDrv.def:
LIBRARY StreamTestDrv
EXPORTS
DRV_Init
DRV_Deinit
DRV_Open
DRV_Close
DRV_Write
DRV_Read
DRV_IOCONTROL
DRV_PowerUp
DRV_PowerDown
DRV_Seek
Windows Embedded CE build process relies on binary image builder (.bib) files to generate the content of the run-time image and to define the final memory layout of the device
Open platform.bib and add the entry as shown below
StreamTestDrv.dll $(_FLATRELEASEDIR)\StreamTestDrv.dll NK SHK
The S and H file indicate that StreamTestDrv.dll is both a system file and a hidden file, located in the flat release directory. K flags instructs Romimage.exe to load the module in kernel space above the memory address 0x80000000.
Registry keys Related to Loading a Driver:
In general, you have two options to load a stream driver under Windows Embedded CE. You can instruct Device Manager to load the driver automatically during the boot sequence by configuring driver settings in the HKLM\Drivers\Builtin registry key,or you can load the driver dynamically through a direct call to ActivateDeviceEx.Either way, Device Manager can load the device driver with the same registry flags and settings.
[HKEY_LOCAL_MACHINE\Drivers\StreamTestDrv]
"Dll"="StreamTestDrv.dll"
"Order"=dword:1
"Index"=dword:1
"Prefix"="DRV"
If you want to load the driver automatically during the boot this should be registry settings.
[HKEY_LOCAL_MACHINE\Drivers\BuiltIn\StreamTestDrv]
"Dll"="StreamTestDrv.dll"
"Order"=dword:1
"Index"=dword:1
"Prefix"="DRV"
#include "stdafx.h"
#include "StreamTestDrv.h"
#include <WinBase.h>
#include <devload.h>
#define SIZE_DRV 100
BOOL APIENTRY DllMain( HANDLE hModule,DWORD ul_reason_for_call,
LPVOID lpReserved)
{
switch(ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
RETAILMSG(1, (TEXT("DLLMAIN: Process Attach\n")));
break;
case DLL_THREAD_ATTACH:
RETAILMSG(TRUE,(TEXT("DLLMAIN: Thread ATTACH \n")));
break;
case DLL_THREAD_DETACH:
RETAILMSG(TRUE,(TEXT(" DLLMAIN: Thread DETACH \n")));
break;
case DLL_PROCESS_DETACH:
RETAILMSG(1, (TEXT("DLLMAIN: Process Detach\n")));
break;
default:
RETAILMSG(1, (TEXT("DLLMAIN: Default\n")));
break;
}
return TRUE;
}
// This is an example of an exported variable
StreamTestDrv_API int nStreamTestDrv=0;
// This is an example of an exported function.
StreamTestDrv_API int fnStreamTestDrv(void)
{
return 42;
}
// This is the constructor of a class that has been exported.
// see StreamTestDrv.h for the class definition
CStreamTestDrv::CStreamTestDrv()
{
return;
}
BOOL DRV_Deinit(DWORD hdeviceContext)
{
RETAILMSG(TRUE, (TEXT("DRV Driver: DD_Deinit\n")));
return TRUE;
}
DWORD DRV_Init(LPCTSTR pContext, LPCVOID lpcContext)
{
RETAILMSG(TRUE, (TEXT("DRV Driver:DD_Init:%s\n"), pContext));
return 0x01;
}
DWORD DRV_Open(DWORD hDeviceContext, DWORD Accesscode, DWORD ShareMode)
{
RETAILMSG(TRUE, (TEXT("DRV Driver:Open\n")));
return ((DWORD) GetCurrentProcess());
}
BOOL DRV_Close(DWORD hDeviceContext)
{
RETAILMSG(TRUE, (TEXT("DRV Driver:Close\n")));
return TRUE;
}
DWORD DRV_Write(DWORD hOpenContext, LPCVOID buffer, DWORD count)
{
RETAILMSG(TRUE, (TEXT("DRV Driver:Write:%s \n"),buffer));
return count;
}
DWORD DRV_Read(DWORD hOpenContext, LPVOID buffer, DWORD count)
{
RETAILMSG(TRUE, (TEXT("DRV Driver:Read\n")));
return count;
}
DWORD DRV_Seek(DWORD hOpenContext, LONG position, DWORD type)
{
RETAILMSG(TRUE, (TEXT("DRV Driver:Seek\n")));
return 0;
}
BOOL DRV_IOCONTROL(DWORD hOpenContext, DWORD dword, PBYTE pBufIn,
DWORD dWLenIn, PBYTE pBufOut, DWORD dWLenOut,
PDWORD pdwordactual)
{
RETAILMSG(TRUE, (TEXT("DRV Driver:IOCONTROL\n")));
return TRUE;
}
void DRV_PowerUp(DWORD hOpenContext)
{
RETAILMSG(TRUE, (TEXT("DRV Driver:PowerUp\n")));
return;
}
void DRV_PowerDown(DWORD hOpenContext)
{
RETAILMSG(TRUE, (TEXT("DRV Driver:PowerDown\n")));
return;
}
StreamTestDrv.def:
LIBRARY StreamTestDrv
EXPORTS
DRV_Init
DRV_Deinit
DRV_Open
DRV_Close
DRV_Write
DRV_Read
DRV_IOCONTROL
DRV_PowerUp
DRV_PowerDown
DRV_Seek
Windows Embedded CE build process relies on binary image builder (.bib) files to generate the content of the run-time image and to define the final memory layout of the device
Open platform.bib and add the entry as shown below
StreamTestDrv.dll $(_FLATRELEASEDIR)\StreamTestDrv.dll NK SHK
The S and H file indicate that StreamTestDrv.dll is both a system file and a hidden file, located in the flat release directory. K flags instructs Romimage.exe to load the module in kernel space above the memory address 0x80000000.
Registry keys Related to Loading a Driver:
In general, you have two options to load a stream driver under Windows Embedded CE. You can instruct Device Manager to load the driver automatically during the boot sequence by configuring driver settings in the HKLM\Drivers\Builtin registry key,or you can load the driver dynamically through a direct call to ActivateDeviceEx.Either way, Device Manager can load the device driver with the same registry flags and settings.
[HKEY_LOCAL_MACHINE\Drivers\StreamTestDrv]
"Dll"="StreamTestDrv.dll"
"Order"=dword:1
"Index"=dword:1
"Prefix"="DRV"
If you want to load the driver automatically during the boot this should be registry settings.
[HKEY_LOCAL_MACHINE\Drivers\BuiltIn\StreamTestDrv]
"Dll"="StreamTestDrv.dll"
"Order"=dword:1
"Index"=dword:1
"Prefix"="DRV"
Comments
Post a Comment