A Demo : How do Warm Reset your device using C# & NETCF V1 and later

一個用 C# + dot NetCF 1.0 and later 的範例程式, 透過 P/Invoke 去存取 Win32 API ,執行 KernalIoControl()去暖開機(保持原有資料不清除),目前測試 Pocket2003 SE Emulator 工作正常,一般有 含 NETCF v1.0 and later 的WinCE Base應該都可以執行,除非OEM為實做相對應的 OAL_IOCTL

using System.Runtime.InteropServices;

namespace RemoveWMUnlock
{

    /// 
    /// Summary description for form.
    /// 
    public class Form1 : System.Windows.Forms.Form
    {
        private static Int32 FILE_DEVICE_HAL = 0x00000101;
        private static Int32 FILE_ANY_ACCESS = 0x0;
        private static Int32 METHOD_BUFFERED = 0x0;
        private static Int32 IOCTL_HAL_REBOOT = ((FILE_DEVICE_HAL) << 16) | ((FILE_ANY_ACCESS) << 14) 
        | ((15) << 2) | (METHOD_BUFFERED);

        private static UInt32 HKEY_CLASSES_ROOT = 0x80000000;
        private static UInt32 HKEY_CURRENT_USER = HKEY_CLASSES_ROOT | 1;
        private static UInt32 HKEY_LOCAL_MACHINE = HKEY_CLASSES_ROOT | 2;
        private static UInt32 HKEY_USERS = HKEY_CLASSES_ROOT | 3;

                [DllImport("coredll.dll")]
                private static extern bool KernelIoControl(Int32 IoControlCode, IntPtr
                                                 InputBuffer, Int32 InputBufferSize, byte[] OutputBuffer, Int32
                                                 OutputBufferSize, ref Int32 BytesReturned);

        private void WarmReset()
        {
            byte[] OutputBuffer = new byte[256];
            Int32 OutputBufferSize, BytesReturned;
            OutputBufferSize = OutputBuffer.Length;
            BytesReturned = 0;

            KernelIoControl(IOCTL_HAL_REBOOT, IntPtr.Zero, 
                0, OutputBuffer, OutputBufferSize, ref BytesReturned);
        }
}
Ref. OAK/INC/Pkfuncs.h, SDK/INC/winioctl.h
Update: 原來 MSDN裡面有一篇相同的文章(還有正體中文版 Orz, http://msdn2.microsoft.com/zh-tw/library/ms172519(VS.80).aspx)
Technorati tags: , , ,
廣告

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

您的留言將使用 WordPress.com 帳號。 登出 / 變更 )

Twitter picture

您的留言將使用 Twitter 帳號。 登出 / 變更 )

Facebook照片

您的留言將使用 Facebook 帳號。 登出 / 變更 )

Google+ photo

您的留言將使用 Google+ 帳號。 登出 / 變更 )

連結到 %s

%d 位部落客按了讚: