加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

golang1.8使用cgo获取进程是否假死

发布时间:2020-12-16 18:14:29 所属栏目:大数据 来源:网络整理
导读:package main import ( "flag" )/* #include stdio.h #include windows.h #include Winuser.h typedef struct EnumFunArg{ HWND hWND; DWORD dwProcessId;}EnumFunArg,*LPEnumFunArg;BOOL CALLBACK lpEnumFunc(HWND hwnd,LPARAM lParam){ EnumFunArg *pArg =
package main

import (
    "flag"
)

/*
#include <stdio.h>
#include <windows.h>
#include <Winuser.h>
typedef struct EnumFunArg
{
    HWND      hWND;
    DWORD    dwProcessId;
}EnumFunArg,*LPEnumFunArg;

BOOL CALLBACK lpEnumFunc(HWND hwnd,LPARAM lParam)
{
    EnumFunArg  *pArg = (LPEnumFunArg)lParam;
    DWORD  processId;
    GetWindowThreadProcessId(hwnd,&processId);
    if( processId == pArg->dwProcessId)
    {
        pArg->hWND = hwnd;
        return FALSE;
    }
    return TRUE;
}

int ReturnWnd(DWORD processID)
{
   BOOL re = FALSE;
   EnumFunArg wi;
   wi.dwProcessId = processID;
   wi.hWND   =  NULL;
   EnumWindows(lpEnumFunc,(LPARAM)&wi);
   if(wi.hWND)
   {
        if (IsHungAppWindow(wi.hWND))
        {
            return 1;
        }
   }
   else
   {
        return -1;
   }
    return 0;
}
*/
import "C"

func main() {
    pid := flag.Int("p",0,"-p 1001")
    flag.Parse()
    h := C.ReturnWnd(C.DWORD(*pid))
    switch h {
    case 0:
        println("程序有响应")
    case 1:
        println("程序无响应")
    case -1:
        println("无法获取窗口")
    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读