最近挺忙的,很久没有写博客了,但是windows mobile开发却一直没有停止过。元旦前一天用我的Dopod575加钱换了个Dopod818,终于实现了Smartphone到Pocket PC的转变,不过Dopod818也是老机器了,似乎刷不了windows mobile 5.0。不过,也不在乎那么多了,最近在研究Pocket PC上的程序开,起初想用EVC++,但是感觉太底层了,现在用起来虽然没有当初那么难,但是对于习惯了C#和delphi编程的我来说,简直太麻烦了,有些编程方式简直是颠覆性的。最终还是决定暂时放弃EVC++,回到封装性不是很好,但是对于开发人员来说比较简单的.net cf上来吧。
好了,闲话少说!传统的Win32编程中对于杀进行使用是很多的,在windows mobile编程中同样可以实现杀进行,不过需要用P/Invoke的方式,也就是使用Coredll.dll中封装的Api函数。具体实现如下:
public const int PROCESS_ALL_ACCESS = 0x000F0000 | 0x00100000 | 0xFFF;
[DllImport("coredll.dll")]
public extern static int GetWindowThreadProcessId(IntPtr hWnd, ref int lpdwProcessId);
[DllImport("coredll.dll")]
public extern static IntPtr OpenProcess(int fdwAccess, int fInherit, int IDProcess);
[DllImport("coredll.dll")]
public extern static bool TerminateProcess(IntPtr hProcess, int uExitCode);
[DllImport("coredll.dll")]
public extern static bool CloseHandle(IntPtr hObject);
public bool Kill()
{
int processId = 0;
GetWindowThreadProcessId(this.Handle, ref processId);
IntPtr hProcess = IntPtr.Zero;
hProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, processId);
if (hProcess.ToInt32() != 0)
{
if (TerminateProcess(hProcess, 1))
{
CloseHandle(hProcess);
return true;
}
else
{
CloseHandle(hProcess);
return false;
}
}
else
{
return false;
}
}
PPC WIndows Mobile 2003se模拟器上测试通过,Good Luck!
基于.net cf C# 实现杀进程
最新推荐文章于 2024-03-28 23:13:18 发布