Windows Mobile 软重启系统

来源:互联网 发布:wdcp php版本升级 编辑:程序博客网 时间:2024/04/30 21:34

在编写Windows Mobile上的应用系统时,因为特殊的业务需要,需要通过软件重启手机,.NET 托管API中不包含该接口,自己封装了一个。
public const uint FILE_DEVICE_HAL = 0x00000101;
        public const uint METHOD_BUFFERED = 0;
        public const uint FILE_ANY_ACCESS = 0;
        public static uint CTL_CODE(uint DeviceType, uint Function, uint Method, uint Access)
        {
            return ((DeviceType << 16) | (Access << 14) | (Function << 2) | Method);
        }

        [System.Runtime.InteropServices.DllImport("Coredll.dll")]
        public extern static uint KernelIoControl
            (
            uint dwIoControlCode,
            IntPtr lpInBuf,
            uint nInBufSize,
            IntPtr lpOutBuf,
            uint nOutBufSize,
            ref uint lpBytesReturned
            );
        /// <summary>
        /// 重启PPC操作
        /// </summary>
        /// <returns></returns>
        public static uint ResetPocketPC()
        {
            uint bytesReturned = 0;
            uint IOCTL_HAL_REBOOT = CTL_CODE(FILE_DEVICE_HAL, 15,
                METHOD_BUFFERED, FILE_ANY_ACCESS);
            return KernelIoControl(IOCTL_HAL_REBOOT, IntPtr.Zero, 0,
                IntPtr.Zero, 0, ref bytesReturned);
        }
在使用的时候,直接调用ResetPocketPC即可。

原创粉丝点击