GetWindowThreadProcessId,无法正常获取进程ID,
我写了一个程序,其他要用到GetWindowThreadProcessId获取进程ID GetWindowThreadProcessId(hWnd,lpdwProcessId)
hWnd
目标窗口句柄
lpdwProcessId
函数在这里返回进程ID,
函数返回值:
线程ID
我好想没有翻译错吧!~~~~~
这个函数执行完成后,lpdwProcessId 这个变量返回了零,进程ID获取不了,
返回值: 返回的好想是线程ID,这个函数执行完后后返回的值非零,应该是线程ID,我也无法验证,下面是源程序 大家帮我看看是哪里错误了
.386
.model flat,stdcall
option casemap :none
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Include 文件定义
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
include windows.inc
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Equ 等值定义
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
IDD_DLG1 EQU 1000 ;主窗口
IDC_BTN2 EQU 1002 ;按钮
IDC_Hd EQU 1001 ;
IDC_SetHd EQU 1003 ;编辑框_句柄
IDC_ID EQU 1004
IDC_SetID EQU 1005 ;编辑框_进程ID
IDC_SetjinchengHd EQU 1006 ;编辑框_进程句柄
IDC_STC1 EQU 1007
ICO_MAIN EQU 100
IDC_CALL EQU 00402360h
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 数据段
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.data?
hInstance dd ?
hWndMain dd ?
ThreadID dd ?
ThreadHa dd ?
CreateThreadID dd ?
.const
lpWindowName db 'MyGame',0
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 代码段
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.code
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_ProcDlgMain proc uses ebx edi esi hWnd,wMsg,wParam,lParam
mov eax,wMsg
.if eax == WM_CLOSE
invoke EndDialog,hWnd,NULL
.elseif eax == WM_INITDIALOG
invoke LoadIcon,hInstance,ICO_MAIN
invoke SendMessage,hWnd,WM_SETICON,ICON_BIG,eax
.elseif eax == WM_COMMAND
mov eax,wParam
.if ax == IDC_BTN2
invoke FindWindow,NULL,addr lpWindowName ;获取窗口句柄
mov hWndMain,eax
invoke SetDlgItemInt,hWnd,IDC_SetHd,hWndMain,TRUE ;把窗口句柄设置到编辑框内
invoke GetWindowThreadProcessId,hWndMain,ThreadID ;获取进程ID
invoke SetDlgItemInt,hWnd,IDC_SetID,ThreadID,TRUE
invoke OpenProcess,PROCESS_ALL_ACCESS,FALSE,ThreadID ;获取进程句柄
mov ThreadHa,eax
invoke SetDlgItemInt,hWnd,IDC_SetjinchengHd,ThreadHa,TRUE
invoke CreateRemoteThread,ThreadHa,NULL,0,IDC_CALL,NULL,0,CreateThreadID
.endif
.else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret
_ProcDlgMain endp
start:
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke DialogBoxParam,hInstance,IDD_DLG1,NULL,offset _ProcDlgMain,NULL
invoke ExitProcess,NULL
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
end start
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
下面是RC资源
#define IDD_DLG1 1000
#define IDC_BTN2 1002
#define IDC_Hd 1001
#define IDC_SetHd 1003
#define IDC_ID 1004
#define IDC_SetID 1005
#define IDC_SetjinchengHd 1006
#define IDC_STC1 1007
#define ICO_MAIN 100
#include <resource.h>
IDD_DLG1 DIALOGEX 10,10,186,72
CAPTION "远程调用CALL"
FONT 8,"MS Sans Serif",0,0,0
STYLE WS_VISIBLE|WS_OVERLAPPEDWINDOW
BEGIN
CONTROL "远程调用 加血",IDC_BTN2,"Button",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP,123,3,57,15
CONTROL "窗口Hd:",IDC_Hd,"Static",WS_CHILDWINDOW|WS_VISIBLE,6,6,41,9
CONTROL "",IDC_SetHd,"Edit",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP,48,3,54,15,WS_EX_CLIENTEDGE
CONTROL "进程ID:",IDC_ID,"Static",WS_CHILDWINDOW|WS_VISIBLE,6,27,33,9
CONTROL "",IDC_SetID,"Edit",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP,48,24,54,15,WS_EX_CLIENTEDGE
CONTROL "",IDC_SetjinchengHd,"Edit",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP,48,42,54,15,WS_EX_CLIENTEDGE
CONTROL "进程Hd:",IDC_STC1,"Static",WS_CHILDWINDOW|WS_VISIBLE,6,45,36,9
END
ICO_MAIN ICON DISCARDABLE "Main.ico"