| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4197 人关注过本帖
标题:获取不到进程句柄 pHandle,请大侠帮帮忙,看哪里出问题了
取消只看楼主 加入收藏
顾海洋凡
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2016-7-9
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:2 
获取不到进程句柄 pHandle,请大侠帮帮忙,看哪里出问题了
大侠,看一下想获得QQ的进程句柄,为什么phandle总是得到0呢?   运行环境win7 32位旗舰版

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal blnheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function writeprocessmemory Lib "kernel32" (ByVal hprocess As Long, ByVal ipbaseaddress As Any, ByVal ipbuffer As Any, ByVal nsize As Long, ipnumberofbyteswritten As Long) As Long
Private Declare Function readprocessmomory Lib "kernel32" (ByVal hprocess As Long, ByVal ipbaseaddress As Any, ByVal ipbuffer As Any, ByVal nsize As Long, ipnumberifbyteswritten As Long) As Long
Private Declare Function closehandle Lib "kernel32" (ByVal hobject As Long) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Sub Command1_Click()
Dim hwnd As Long
hwnd = FindWindow(vbNullString, "QQ")  '得到窗口句柄
Label3.Caption = hwnd
If hwnd = 0 Then

Label1.Caption = "程序未运行"  '验证是否得到有效窗口句柄
Else
Label1.Caption = "程序已运行"
End If
Dim pid As Long
Dim pHandle As Long
GetWindowThreadProcessId hwnd, pid      '得到进程标识符
Label2.Caption = pid
pHandle = OpenProcess(PROCESS_ALL_ACCESS, False, pid) '通过进程标识符获得进程句柄
If pHandle = 0 Then
MsgBox "couldn 't get a process handle!"
Else
Label4.Caption = pHandle

End If
End Sub



[此贴子已经被作者于2016-7-28 15:23编辑过]

搜索更多相关主题的帖子: 运行环境 旗舰 
2016-07-28 15:09
顾海洋凡
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2016-7-9
收藏
得分:0 
回复 楼主 顾海洋凡
图片附件: 游客没有浏览图片的权限,请 登录注册
图片附件: 游客没有浏览图片的权限,请 登录注册



这是运行前和运行后的结果,
2016-07-28 15:24
顾海洋凡
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2016-7-9
收藏
得分:0 
回复 4楼 liuzhaoyzz
用您的方法已经解决了——非常感谢
2016-08-02 15:23
快速回复:获取不到进程句柄 pHandle,请大侠帮帮忙,看哪里出问题了
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.022210 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved