为什么取不出进程句柄,
Public Class Form1
Public Declare Function FindWindow Lib "user32 " Alias "FindWindowA " (ByVal hwnd As String, ByVal lpText As String) As Integer
Public Declare Function GetWindowThreadProcessId Lib "user32 " Alias "GetWindowThreadProcessId " (ByVal hwnd As Integer, ByVal lpText As Integer) As Integer
Public Declare Function OpenProcess Lib "kernel32 " (ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Integer, ByVal dwProcessId As Integer) As Integer
Public Const PROCESS_ALL_ACCESS = &H1F0FFF
Public Declare Function ReadProcessMemory Lib "kernel32.dll " ( _
ByVal hProcess As Integer, _
ByVal lpBaseAddress As Integer, _
ByRef lpBuffer As Object, _
ByVal nSize As Integer, _
ByRef lpNumberOfBytesWritten As Integer) As Integer
Public Declare Function CloseHandle Lib "kernel32 " (ByVal hObject As Integer) As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim jb As Integer
Dim pid As Integer
Dim hProcess As Integer
jb = FindWindow( "SciCalc ", Nothing)
TextBox1.Text = jb.ToString
GetWindowThreadProcessId(jb, pid)
TextBox2.Text = pid.ToString
hProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, pid)
TextBox3.Text = hProcess.ToString
End Sub
End Class
[解决办法]
看这个:
http://community.csdn.net/Expert/topic/4881/4881190.xml?temp=.8271143
[解决办法]
取到了,是声明的问题,GetWindowThreadProcessId的声明改为:
Public Declare Function GetWindowThreadProcessId Lib "user32 " (ByVal hwnd As Integer, ByRef lpdwProcessId As Integer) As Integer