技术积累,经验交流---Design,Ajax,Web Service,Remoting,SQL,Javascript,C#,ASP.net,CSS,Winform,vs2005,VB.net,XML,PDA,Mobile,Saas

细节决定成败!

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  83 随笔 :: 2 文章 :: 65 评论 :: 9 引用
PocketPC运行程序经常由于某些不确定的因素,导致程序就死在那里了.但在PocketPC上又没有象桌面Windows一样的任务管理器.所有出现了此问题要么就等个半天,要么就硬重启.下面给大家介绍一段软重启的代码.看过就可以直接拿来使用.
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace ResetPocketPC
{
  
class ResetPocketPC
  
{
    
public const uint FILE_DEVICE_HAL = 0x00000101;
    
public const uint METHOD_BUFFERED = 0;
    
public const uint FILE_ANY_ACCESS = 0;
    
public   uint CTL_CODE(uint DeviceType, uint Function, uint Method, uint Access)
    
{
      
return ((DeviceType << 16| (Access << 14| (Function << 2| Method);
    }

    [DllImport(
"Coredll.dll")]
    
public extern static uint KernelIoControl
    (
        
uint dwIoControlCode,
        IntPtr lpInBuf,
        
uint nInBufSize,
        IntPtr lpOutBuf,
        
uint nOutBufSize,
        
ref uint lpBytesReturned
    );
    
//调用此方法软重启
    public  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, 0ref bytesReturned);
    }


  }

}


//调用
 private void button1_Click(object sender, EventArgs e)
    
{
      DialogResult r 
= MessageBox.Show(
        
"你确定要重启吗?",
        
"Test",
        MessageBoxButtons.YesNo,
        MessageBoxIcon.Question,
        MessageBoxDefaultButton.Button2
    );

      
if (r == DialogResult.Yes)
      
{
        ResetMobile RsMobile 
= new ResetMobile();
        RsMobile.ResetPocketPC();

      }


    }
posted on 2007-10-30 16:54 ruinet 阅读(285) 评论(0)  编辑 收藏 网摘 所属分类: Mobile & Embedded



发表评论

昵称: [登录] [注册]

主页:

邮箱:(仅博主可见)

评论内容:

  登录  注册

[使用Ctrl+Enter键快速提交评论]

0 943263




相关文章:

相关链接:

free web counter