Here is a short guide on how to create your very own driver in Windows CE:
IF BSP_DRIVERSHELL
IF _WINCEOSVER=600
${drivername}.dll $(_FLATRELEASEDIR)\${drivername}.dll NK K
ELSE
${drivername}.dll $(_FLATRELEASEDIR)\${drivername}.dll NK
ENDIF
ENDIF
"Prefix"="XXX"
"Dll"="${drivername}.dll"
"Order"=dword:4
EXPORTS
XXX_Init
XXX_Deinit
XXX_Read
XXX_Open
XXX_Close
XXX_IOControl
#include <windows.h>
#include <devload.h>
#include "bsp.h"
extern "C"
BOOL WINAPI DllMain(HANDLE hInstDll, DWORD dwReason, LPVOID lpvReserved)
{
BOOL XXX_Close(DWORD hOpenContext)
{
return TRUE;
}
BOOL XXX_IOControl(DWORD hOpenContext, DWORD dwCode, PBYTE pBufIn,
- In solution explorer, go to C:\WINCE800\platform\${whatever board}\SRC\DRIVERS
- right click driver and press "Add"->"New subproject..."
- Select WCE Dynamic Link library and empty project.
- Add the following in ${drivername}.bib:
IF BSP_DRIVERSHELL
IF _WINCEOSVER=600
${drivername}.dll $(_FLATRELEASEDIR)\${drivername}.dll NK K
ELSE
${drivername}.dll $(_FLATRELEASEDIR)\${drivername}.dll NK
ENDIF
ENDIF
- Add the following in ${drivername}.reg:
"Prefix"="XXX"
"Dll"="${drivername}.dll"
"Order"=dword:4
- Add the following in ${drivername}.def:
EXPORTS
XXX_Init
XXX_Deinit
XXX_Read
XXX_Open
XXX_Close
XXX_IOControl
Note that XXX should be fixed to 3 letters. The functions defined should match the functions in cpp file
- Add the following in ${drivername}.cpp:
#include <windows.h>
#include <devload.h>
#include "bsp.h"
extern "C"
BOOL WINAPI DllMain(HANDLE hInstDll, DWORD dwReason, LPVOID lpvReserved)
{
UNREFERENCED_PARAMETER(lpvReserved);
switch (dwReason) {
case DLL_PROCESS_ATTACH:
switch (dwReason) {
case DLL_PROCESS_ATTACH:
DEBUGREGISTER((HMODULE)hInstDll);
DisableThreadLibraryCalls((HMODULE)hInstDll);
break;
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
DWORD XXX_Init(LPCTSTR pContext)
{
return 1;
}
DWORD XXX_Read(DWORD hOpenContext, LPVOID pBuffer, DWORD Count)
{
return 0;
}
BOOL XXX_Deinit(DWORD hDeviceContext)
{
return TRUE;
}
DWORD XXX_Open(DWORD hDeviceContext, DWORD AccessCode, DWORD ShareMode)
{
return 1;
}
return TRUE;
}
DWORD XXX_Init(LPCTSTR pContext)
{
return 1;
}
DWORD XXX_Read(DWORD hOpenContext, LPVOID pBuffer, DWORD Count)
{
return 0;
}
BOOL XXX_Deinit(DWORD hDeviceContext)
{
return TRUE;
}
DWORD XXX_Open(DWORD hDeviceContext, DWORD AccessCode, DWORD ShareMode)
{
return 1;
}
BOOL XXX_Close(DWORD hOpenContext)
{
return TRUE;
}
BOOL XXX_IOControl(DWORD hOpenContext, DWORD dwCode, PBYTE pBufIn,
DWORD dwLenIn, PBYTE pBufOut, DWORD dwLenOut, PDWORD pdwActualOut)
{
return TRUE;
}
{
return TRUE;
}
- In Drivers\dir, add the DLL project name
- In C:\WINCE800\platform\${whatever board}\FILES\platform.reg, Add the follwong line:
- #include "$(_winceroot)\platform\${whatever board}SRC\DRIVERS\USBMANAGER\${drivername}.reg"
- In C:\WINCE800\platform\${whatever board}\FILES\platform.bib, Add the following line:
- ${drivername}.dll $(_FLATRELEASEDIR)\${drivername}.dll
- Try building the driver alone first for some minor bugs that might apear.
- Build everything and the driver should work.
Comments
Post a Comment