Tuesday 8 January 2008

Windows CE 5.0 device driver development-Part 2

How ca we build a driver for Device manufacturer specific functionalities and use it from an apps without using device IOCTLs:



1. lets make a folder DeviceFunc

2. make a new file DeviceFunc.cpp in the above folder

lets edit this as this will be our main device driver source file.



#include



#ifdef __cplusplusextern "C"

{

#endif



void GreenLEDControl(BOOL OnOff )

{

RETAILMSG (1, (TEXT(" Green LED is currently=%d\r\n"), OnOff ));

}

void

(BOOL OnOff )

{

RETAILMSG (1, (TEXT(" RED LED is currently=%d\r\n"), OnOff ));

}

void BacklightControl(BOOL OnOff )

{

RETAILMSG (1, (TEXT(" Backlight is currently =%d\r\n"), OnOff ));

}

void WirelessControl(BOOL OnOff )

{

RETAILMSG (1, (TEXT(" Wireless is currently=%d\r\n"), OnOff ));

}

void DisplayControl(BOOL OnOff )

{

RETAILMSG (1, (TEXT(" Display is currently=%d\r\n"), OnOff ));

}

#ifdef __cplusplus

}

#endif



BOOL WINAPI DllEntry( HANDLE hinstDLL, DWORD Op, LPVOID lpvReserved )

{

return TRUE;
}



now we have the code lets make a def file which will export these functions:



LIBRARY DeviceFunc
EXPORTS

GreenLEDControl

RedLEDControl

BacklightControl

WirelessControl

DisplayControl



and now lets make a sources file:



TARGETNAME=DeviceFunc



RELEASETYPE=PLATFORM



TARGETTYPE=DYNLINK


TARGETLIBS= \$(_COMMONSDKROOT\lib\$(_CPUINDPATH\coredll.lib \

$(_COMMONOAKROOT)\lib\$(_CPUINDPATH)\ceddk.lib


DEFFILE=DeviceFunc.def


DLLENTRY=DllEntry


SOURCES= DeviceFunc.cpp





now we have made copy a makefile from a standard wince driver directory and compile the folder.

you will get a DeviceFunc.dll file.



Now to the next step, how can we access these exported functions on our device by other drivers\applications:



Lets first take an app implementation:

typedef void (*PFN_BacklightControl)(BOOL fOn);

HINSTANCE gDeviceFuncDll = NULL;

gDeviceFuncDll =LoadLibrary(TEXT("DeviceFunc.dll"));

pfnBrightnessUp = (PFN_BacklightControl)GetProcAddress(gDeviceFuncDll , TEXT("BacklightControl"));

No comments: