下面是得到托盘的图标的代码,我想把readprocessmemory用copymemory替换,但是总不成功,那位高手帮忙?
Private Type TBBUTTON
iBitmap As Long
idCommand As Long
fsState As Byte
fsStyle As Byte
bReserved1 As Byte
bReserved2 As Byte
dwData As Long
iString As Long
End Typedim Tmplong as long
dim TbBtn as TBBUTTON
hProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, lngPID) 'lngPID其实为explorer进程的id,hProcess为explorer的句柄
lngAddress = VirtualAllocEx(hProcess, ByVal 0&, ByVal 4096&, MEM_COMMIT, PAGE_READWRITE) '在hProcess中申请一块内存
lngButtons = SendMessage(lngTray, TB_BUTTONCOUNT, 0, ByVal 0) ‘lngButtons为托盘图标的个数、
For i = 0 To lngButtons - 1
'ByVal lngAddres是接受按钮信息的TBBUTTON structure的指针:Pointer to the TBBUTTON structure that receives the button information.
'sendmessage的返回消息要保存在目标进程里(此为一种进程数据的自我保护,以防止其他进程的误操作导致操作越权等致命错误)
Ret = SendMessage(lngTray, TB_GETBUTTON, i, ByVal lngAddress) '
Ret = ReadProcessMemory(hProcess, ByVal lngAddress + 16, ByVal VarPtr(lngTextAdr), 4, ByVal 0)
'CopyMemory ByVal VarPtr(Tmplong), ByVal lngAddress+16 , 4 '这句代码想代替上面的一句代码,但是也不成功
'CopyMemory ByVal VarPtr(TbBtn), ByVal lngAddress, LenB(TbBtn) '这句代码想直接从lngAddress地址读出图标的信息,但是不成功
If lngTextAdr <> -1 Then
'ReadProcessMemory最后一参数返回实际读取的字节数,若设为0,则忽略此参数。
Ret = ReadProcessMemory(hProcess, ByVal lngTextAdr, ByVal VarPtr(strBuff(0)), 1024, ByVal 0)
Ret = ReadProcessMemory(hProcess, ByVal lngAddress + 12, ByVal VarPtr(lngHwndAdr), 4, ByVal 0)
Ret = ReadProcessMemory(hProcess, ByVal lngHwndAdr, ByVal VarPtr(lngHwnd), 4, ByVal 0)
Ret = ReadProcessMemory(hProcess, ByVal lngAddress + 4, ByVal VarPtr(lngButtonID), 4, ByVal 0)
strText = Left(strBuff, InStr(strBuff, Chr(0)) - 1)
debug.print “图标句柄" & lngHwnd
debug.print ”图标ID“ & lngButtonID
debug.print ”图标显示字串" & strText
End If
Next i
Private Type TBBUTTON
iBitmap As Long
idCommand As Long
fsState As Byte
fsStyle As Byte
bReserved1 As Byte
bReserved2 As Byte
dwData As Long
iString As Long
End Typedim Tmplong as long
dim TbBtn as TBBUTTON
hProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, lngPID) 'lngPID其实为explorer进程的id,hProcess为explorer的句柄
lngAddress = VirtualAllocEx(hProcess, ByVal 0&, ByVal 4096&, MEM_COMMIT, PAGE_READWRITE) '在hProcess中申请一块内存
lngButtons = SendMessage(lngTray, TB_BUTTONCOUNT, 0, ByVal 0) ‘lngButtons为托盘图标的个数、
For i = 0 To lngButtons - 1
'ByVal lngAddres是接受按钮信息的TBBUTTON structure的指针:Pointer to the TBBUTTON structure that receives the button information.
'sendmessage的返回消息要保存在目标进程里(此为一种进程数据的自我保护,以防止其他进程的误操作导致操作越权等致命错误)
Ret = SendMessage(lngTray, TB_GETBUTTON, i, ByVal lngAddress) '
Ret = ReadProcessMemory(hProcess, ByVal lngAddress + 16, ByVal VarPtr(lngTextAdr), 4, ByVal 0)
'CopyMemory ByVal VarPtr(Tmplong), ByVal lngAddress+16 , 4 '这句代码想代替上面的一句代码,但是也不成功
'CopyMemory ByVal VarPtr(TbBtn), ByVal lngAddress, LenB(TbBtn) '这句代码想直接从lngAddress地址读出图标的信息,但是不成功
If lngTextAdr <> -1 Then
'ReadProcessMemory最后一参数返回实际读取的字节数,若设为0,则忽略此参数。
Ret = ReadProcessMemory(hProcess, ByVal lngTextAdr, ByVal VarPtr(strBuff(0)), 1024, ByVal 0)
Ret = ReadProcessMemory(hProcess, ByVal lngAddress + 12, ByVal VarPtr(lngHwndAdr), 4, ByVal 0)
Ret = ReadProcessMemory(hProcess, ByVal lngHwndAdr, ByVal VarPtr(lngHwnd), 4, ByVal 0)
Ret = ReadProcessMemory(hProcess, ByVal lngAddress + 4, ByVal VarPtr(lngButtonID), 4, ByVal 0)
strText = Left(strBuff, InStr(strBuff, Chr(0)) - 1)
debug.print “图标句柄" & lngHwnd
debug.print ”图标ID“ & lngButtonID
debug.print ”图标显示字串" & strText
End If
Next i
而readprocessmemory是在其它进程空间进程操作,copymemory没法代替readprocessmemory,是不是可以
用CreateRemoteThread在别的进程中进行copymemory就不知道了
那还是老老实实用ReadProcessMemory吧