How to shutdown/reboot a mobile device (Win CE 6.0) with EMDK 2.6?

12k views Asked by At

I'm trying to shutdown/reboot my Motorola MC9190 with the EMDK 2.6, but I can't figure out how to achieve this. May someone point me in the right direction in which namespace I can find methods for this or post an example? The Helpfiles just offer me methods the reboot several parts like RF or WLAN :/

Thanks in advance.

PS: I can't use external components as a workaround!

3

There are 3 answers

0
Snake Sanders On BEST ANSWER

I usually use this snippet, below you will see for both CE and WM (commented). You just need to call the ExitWindowsEx(2,0) for CE, and SetSystemPowerState(NULL; POWER_STATE_RESET, 0) for Windows Mobile.

The following sample delays the reboot 48hrs.

// REBOOT.cpp : Defines the entry point for the console application. //

#include "stdafx.h"
#include <windows.h>
#include <commctrl.h>
#include <Pm.h>

int _tmain(int argc, _TCHAR* argv[])
{
    SYSTEMTIME tSysTime;
    GetSystemTime(&tSysTime);

    if (tSysTime.wYear!= 2005)
    {
        int delay = 1000 *60 * 60 * 48;// 48 Hrs
        Sleep(delay);

        //windows Mobile
        //ExitWindowsEx(2,0);

        //windows CE
        return (int)SetSystemPowerState(NULL, POWER_STATE_RESET, 0);

    }

    return 0;
}
0
mesutpiskin On

Use to this code for reboot

[DllImport("coredll.dll")]
static extern int SetSystemPowerState(string psState, int StateFlags, int Options);
        const int POWER_FORCE = 4096;
        const int POWER_STATE_RESET = 0x00800000;


        private void SoftReset()
        {
            SetSystemPowerState(null, POWER_STATE_RESET, POWER_FORCE);
        }  

(include System.Runtime.InteropServices)

0
montelof On

This is the code I use to soft reset a Windows CE Device

    [DllImport("coredll.dll")]
    private static extern bool KernelIoControl(Int32 IoControlCode, IntPtr InputBuffer, Int32 InputBufferSize, byte[] OutputBuffer, Int32 OutputBufferSize, ref Int32 BytesReturned);
    private const uint FILE_DEVICE_HAL = 0x00000101;
    private const uint METHOD_BUFFERED = 0;
    private const uint FILE_ANY_ACCESS = 0;

    private static uint CTL_CODE(uint DeviceType, uint Function, uint Method, uint Access)
    {
        return ((DeviceType << 16) | (Access << 14) | (Function << 2) | Method);
    }

    public static void softReset()
    {
        byte[] OutputBuffer = new byte[256];
        Int32 OutputBufferSize, BytesReturned;
        OutputBufferSize = OutputBuffer.Length;
        BytesReturned = 0;

        Int32 IOCTL_HAL_REBOOT = (Int32)CTL_CODE(FILE_DEVICE_HAL, 15, METHOD_BUFFERED, FILE_ANY_ACCESS);

        KernelIoControl(IOCTL_HAL_REBOOT, IntPtr.Zero, 0, OutputBuffer, OutputBufferSize, ref BytesReturned);
    }