private string GetTVItemTextEx(IntPtr wndTreeView, IntPtr item) { const int TVIF_TEXT = 0x0001; const int MAX_TVITEMTEXT = 512; Interop.TVITEM tvi = new Interop.TVITEM(); tvi.mask = TVIF_TEXT; tvi.hItem = item; tvi.cchTextMax = MAX_TVITEMTEXT; // set address to remote buffer immediately following the tvItem tvi.pszText = (IntPtr)(lpRemoteBuffer.ToInt32() + Marshal.SizeOf(typeof(Interop.TVITEM))); // copy local tvItem to remote buffer bool bSuccess = Interop.WriteProcessMemory(hProcess, lpRemoteBuffer, ref tvi, Marshal.SizeOf(typeof(Interop.TVITEM)), IntPtr.Zero); if (!bSuccess) { ShowErrorMessage(new SystemException("Failed to write to process memory")); } Interop.SendMessage(wndTreeView, Interop.TVM_GETITEMW, IntPtr.Zero, lpRemoteBuffer); // copy tvItem back into local buffer (copy whole buffer because we don't yet know how big the string is) bSuccess = Interop.ReadProcessMemory(hProcess, lpRemoteBuffer, lpLocalBuffer, dwBufferSize, IntPtr.Zero); if (!bSuccess) { ShowErrorMessage(new SystemException("Failed to read from process memory")); } return(Marshal.PtrToStringUni((IntPtr)(lpLocalBuffer.ToInt32() + Marshal.SizeOf(typeof(Interop.TVITEM))))); }
private string GetTVItemTextEx(IntPtr wndTreeView, IntPtr item) { const int TVIF_TEXT = 0x0001; const int MAX_TVITEMTEXT = 512; // set address to remote buffer immediately following the tvItem var nRemoteBufferPtr = _lpRemoteBuffer.ToInt64() + Marshal.SizeOf(typeof(Interop.TVITEM)); var tvi = new Interop.TVITEM { mask = TVIF_TEXT, hItem = item, cchTextMax = MAX_TVITEMTEXT, pszText = (IntPtr)nRemoteBufferPtr }; // copy local tvItem to remote buffer var success = Interop.WriteProcessMemory(_hProcess, _lpRemoteBuffer, ref tvi, Marshal.SizeOf(typeof(Interop.TVITEM)), IntPtr.Zero); if (!success) ShowErrorMessage(new SystemException("Failed to write to process memory")); Interop.SendMessage(wndTreeView, Interop.TVM_GETITEMW, IntPtr.Zero, _lpRemoteBuffer); // copy tvItem back into local buffer (copy whole buffer because we don't yet know how big the string is) success = Interop.ReadProcessMemory(_hProcess, _lpRemoteBuffer, _lpLocalBuffer, BufferSize, IntPtr.Zero); if (!success) ShowErrorMessage(new SystemException("Failed to read from process memory")); var nLocalBufferPtr = _lpLocalBuffer.ToInt64() + Marshal.SizeOf(typeof(Interop.TVITEM)); return Marshal.PtrToStringUni((IntPtr)nLocalBufferPtr); }