Dim hProc, lpText, lpExText, lpItem, lpExItem As IntPtr
Dim nProcId As Integer = Process.GetProcessesByName(APP_NAME)(0).Id
hProc = OpenProcess(PROCESS_VM_OPERATION Or PROCESS_VM_READ Or PROCESS_VM_WRITE, False, nProcId)
' write string in external process's memory
Dim strText As String = " "
lpText = Marshal.StringToHGlobalAnsi(strText)
Dim nSizeText As Integer = strText.Length * Marshal.SizeOf("a"c)
lpExText = VirtualAllocEx(hProc, 0, nSizeText, MEM_COMMIT, PAGE_READWRITE)
Dim nResult As Integer '= WriteProcessMemory(hProc, lpExText, lpText, nSizeText, 0&)
' write LVITEM structure in external process's memory
Dim item As LVITEM
item.mask = LVIF_TEXT
item.iItem = nIndex
item.pszText = lpExText
item.cchTextMax = nSizeText
Dim nSizeItem As Integer = Marshal.SizeOf(item)
lpItem = Marshal.AllocHGlobal(nSizeItem)
Marshal.StructureToPtr(item, lpItem, True)
lpExItem = VirtualAllocEx(hProc, 0, nSizeItem, MEM_COMMIT, PAGE_READWRITE)
nResult = WriteProcessMemory(hProc, lpExItem, lpItem, nSizeItem, 0&)
' get list view item text
Dim nLength As Integer = SendMessage(hctrl, LVM_GETITEMTEXTA, nIndex, lpExItem)
' read the list view item text from external process's momery
nResult = ReadProcessMemory(hProc, lpExText, lpText, nSizeText, 0&)
strText = Marshal.PtrToStringAnsi(lpText)
' clean momery
nResult = VirtualFreeEx(hProc, lpExText, 0, MEM_RELEASE)
lpExText = IntPtr.Zero
nResult = VirtualFreeEx(hProc, lpExItem, 0, MEM_RELEASE)
lpExItem = IntPtr.Zero
Marshal.FreeHGlobal(lpText)
lpText = IntPtr.Zero
Marshal.FreeHGlobal(lpItem)
lpItem = IntPtr.Zero
CloseHandle(hProc)
hProc = IntPtr.Zero
Return strText
以上代码在32位系统上可以正常运行,但换到64位系统上就不行,sendmessage函数总是返回0,我试过用sendmessage发送LVM_GETITEMRECT消息在64位系统上是可以成功的,所以我觉得也许是字符串格式造成的问题,但我把LVM_GETITEMTEXTA改为LVM_GETITEMTEXTW还是不行,恳请哪位大虾指点迷津,最好说具体些,给分100,谢谢啊~~
3 个解决方案
#1
不晓得。。。64bit下很多工具失效
#2
在64位机上,你可能要正确的处理消息Message中的两个参数高低位的问题,如果处理的不正确就不会得到正确的结果,这就像从16位到32位一样.
#3
具体是应该怎么处理?应该注意什么方面?谢谢
#1
不晓得。。。64bit下很多工具失效
#2
在64位机上,你可能要正确的处理消息Message中的两个参数高低位的问题,如果处理的不正确就不会得到正确的结果,这就像从16位到32位一样.
#3
具体是应该怎么处理?应该注意什么方面?谢谢