求VB高手,解决读取外部程序中的数据的问题
我调用了一个外部程序A,从VB窗口输入数据到外部程序A的问题已经解决,由于外部程序A在接收到VB窗口输入的数据时会在它的一个内部子窗口产生另一个数据X,我怎么获得这个Y并把它输出到VB的text中。
流程为: VB→ 输入数据X→ 外部程序A→计算结果Y(在外部程序的窗体中显示)→how?→how?→VB
[解决办法]
我以前写的个东东
太长了分两段吧
先是API
Option Explicit
' ---获取进程PID---
Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
Private Declare Function Process32First Lib "kernel32" (ByVal hSnapShot As Long, uProcess As ProcessEntry32) As Long
Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapShot As Long, uProcess As ProcessEntry32) As Long
Const TH32CS_SNAPHEAPLIST = &H1
Const TH32CS_SNAPPROCESS = &H2
Const TH32CS_SNAPTHREAD = &H4
Const TH32CS_SNAPMODULE = &H8
Const TH32CS_SNAPALL = (TH32CS_SNAPHEAPLIST Or TH32CS_SNAPPROCESS Or TH32CS_SNAPTHREAD Or TH32CS_SNAPMODULE)
Const TH32CS_INHERIT = &H80000000
Const MAX_PATH As Integer = 260
Private Type ProcessEntry32
dwSize As Long
cntUsage As Long
th32ProcessID As Long
th32DefaultHeapID As Long
th32ModuleID As Long
cntThreads As Long
th32ParentProcessID As Long
pcPriClassBase As Long
dwFlags As Long
szExeFile As String * MAX_PATH
End Type
' ---获取窗体句柄---
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetParent Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hWnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, lpdwprocessid As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hWnd As Long) As Long
' ---查找窗体常量---
Const GW_HWNDFIRST = &H0
Const GW_HWNDLAST = &H1
Const GW_HWNDNEXT = &H2
Const GW_HWNDPREV = &H3
Const GW_OWNER = &H4
Const GW_CHILD = &H5
' ---读取内存---
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function ReadProcessMemory Lib "kernel32.dll" (ByVal hProcess As Long, ByVal lpBaseAddress As Long, ByRef lpBuffer As Any, ByVal nSize As Long, ByRef lpNumberOfBytesWritten As Long) As Long
' ---读写内存常量---
Const PROCESS_ALL_ACCESS = &H1F0FFF
Const PROCESS_TERMINATE = &H1
Const PROCESS_VM_OPERATION = &H8