I thought that it might be useful to have a shell of a stream interface driver that I could use to start developing a driver from. I can’t believe that I never created this before, but here it is.
I called this driver “DriverShell” because that is all that it is, a shell of a driver. This is a very basic starting point for creating a new driver. I have tested that this driver actually will be loaded by the Device Manager, which is a stumbling block that some developers run into.
The only real work that this driver does is to open the registry key that is passed into XXX_Init(), but it doesn’t read any values, handle any interrupts, allocate any virtual addresses. What I did include is the functions that are needed to have a driver be loaded by the Device Manager, a sources file that will build the driver, a bib file to include the driver in the OS image and a reg file to add the driver to the registry.
If you want to use this, you need to:
-
Create a folder under Drivers for this driver
-
Create the files listed below in the new folder and copy the content to the files.
-
Add the new folder name to its parent folder Dirs file
-
Copy the contents of DriverShell.bib to your platform.bib
-
Copy the contents of DriverShell.reg to your platform.reg
-
Set the environment variable BSP_DRIVERSHELL=1
-
Do a sanity build and test to see that the driver loads, you don’t trust me do you?
-
Rename the Folder to give it a suitable name for your purposes
-
Rename the functions (XXX_Init works, but you should use 3 letters that make more sense)
-
Change the DriverShell.def to reflect your function names
-
Add some real content to the functions
Files To Create:
DriverShell.bib
MODULES
IF BSP_DRIVERSHELL
IF _WINCEOSVER=600
DriverShell.dll $(_FLATRELEASEDIR)\DriverShell.dll NK K
ELSE
DriverShell.dll $(_FLATRELEASEDIR)\DriverShell.dll NK
ENDIF
ENDIF
DriverShell.reg
IF BSP_DRIVERSHELL
[HKEY_LOCAL_MACHINE\Drivers\BuiltIn\DriverShell]
"Dll"="DriverShell.dll"
"Order"=dword:4
"Prefix"="XXX"
ENDIF
Sources
TARGETNAME=DriverShell
RELEASETYPE=PLATFORM
TARGETTYPE=DYNLINK
DEFFILE=DriverShell.def
DLLENTRY=DllEntry
TARGETLIBS= $(_COMMONSDKROOT)\lib\$(_CPUINDPATH)\coredll.lib
SOURCES=DriverShell.c
Makefile.inc
#
# DO NOT EDIT THIS FILE!!! Edit .\sources. if you want to add a new source
# file to this component. This file merely indirects to the real make file
# that is shared by all the components of Windows CE.
#
!INCLUDE $(_MAKEENVROOT)\makefile.def
DriverShell.def
LIBRARY DriverShell
EXPORTS XXX_Init
XXX_Deinit
XXX_Open
XXX_Close
XXX_Read
XXX_Write
XXX_Seek
XXX_PowerDown
XXX_PowerUp
XXX_IOControl
DriverShell.c
#include <windows.h>
#include <Devload.h>
BOOL XXX_Deinit( DWORD hDeviceContext )
{
return TRUE;
}
DWORD XXX_Init(ULONG RegistryPath)
{
HKEY hKey;
RETAILMSG( 1, (TEXT("XXX_Init\n")));
hKey = OpenDeviceKey((LPCTSTR)RegistryPath);
if ( !hKey ) {
RETAILMSG(1, (TEXT("Failed to open devkeypath,\r\n")));
}
else
{
// Read values from registry if needed
RegCloseKey (hKey);
}
return TRUE;
}
BOOL WINAPI DllEntry(HINSTANCE DllInstance, ULONG Reason, LPVOID Reserved)
{
RETAILMSG( 1, (TEXT("DriverShell: DllEntry\n")));
return TRUE;
}
VOID XXX_PowerUp(DWORD hDeviceContext )
{
}
VOID XXX_PowerDown(DWORD hDeviceContext)
{
}
DWORD XXX_Open(DWORD hDeviceContext, DWORD AccessCode, DWORD ShareMode)
{
return hDeviceContext;
}
BOOL XXX_Close(DWORD hOpenContext)
{
return TRUE;
}
DWORD XXX_Read(DWORD hOpenContext, LPVOID pBuffer, DWORD Count)
{
return 0;
}
DWORD XXX_Write(DWORD hOpenContext, LPCVOID pSourceBytes, DWORD NumberOfBytes)
{
return 0;
}
DWORD XXX_Seek(DWORD hOpenContext, long Amount, DWORD Type)
{
return 0;
}
BOOL XXX_IOControl(DWORD hOpenContext, DWORD dwCode, PBYTE pBufIn, DWORD dwLenIn, PBYTE pBufOut, DWORD dwLenOut, PDWORD pdwActualOut)
{
BOOL RetVal = TRUE;
switch(dwCode)
{
default:
RetVal = FALSE;
break;
}
return RetVal;
}
Copyright © 2008 – Bruce Eitman
All Rights Reserved