Sunday, April 25, 2010

Calling Native Code from C#. (.Net CF in WM)

One of My Colleague was trying to configure a GPIO pin from a C# Application. To call the native code we have P- Invoke in C#. But sometimes it confuses,what data types to use while declaring the function in C# and whether that type is compatible in C/C++.

Another Colleague suggested a smart way of handling these type of issues.

If you are not passing any input to the Native code from C#(or if it is not required to pass), then simply define a a function with no input and do all the processing in the native code itself. In Native code you can call any system APIs like DeviceIoctl or MmMapIoSpace and have any data types you need to.

This may help the beginners to catch up !!

Friday, April 23, 2010

Cold booting Windows CE 6.0 Terminal

Hi All,
Yesterday I was trying to find how to cold boot a CE6.0 terminal from a Application.
You could call KerneIoctl function with IOCTL_HAL_REBOOT to warm boot the system (Soft Reset) and if you call SetCleanRebootFlag() beofore the Ioctl call, so you can do Cold Boot (Hard Reset).
In CE5.0, WM6.1 and WM 6.5, these calls were directly possible from the application itself. But in CE 6.0 as the memory architecture was changed, only limited IOCTLs are supported by default from user Mode Applications and Drivers. (But OEMs can modify this behavior and may support more IOCTLs).

There is a simple alternate method worked for me, which is using PM API SetSystemPowerState().
PM has two state called coldreboot (Cold Boot) and reboot(Warm Boot).
Warm Boot has a state defined in PM.H as POWER_STATE_RESET, but I believe Cold boot is not documented properly. POWER_STATE_BOOT didn't do Cold boot as expected.

Cold Boot:

SetSystemPowerState(L"reboot",FALSE,POWER_FORCE); or

when the SetSysmPowerstate is called with coldreboot string, PM does call SetCleanRebootFlag and KernelIoctl with IOCTL_HAL_REBOOT.

I believe Application developers can make use of PM API to do Cold and Warm Boots.

I have tested these APIs on Motorola MPA 2.0 CE Terminal.

Please correct me, If Iam Wrong.