473,657 Members | 2,389 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting Items from ListView from other application

Hi
If it is wrong newsgroup, please let me know where to find the answer.
I am trying to get item text form ListView (there are few items and 5
columns) from other application (application written in MFC). As I know I
have to allocate memory in target application address space, send a message
and than read from allocated memory. But I still doing something wrong and
can't find correct solution. I fell I am close to it. Please find code below
(C#) :

[StructLayout( LayoutKind.Sequ ential)]
public struct LV_ITEMA
{
public int mask;
public int iItem;
public int iSubItem;
public int state;
public int stateMask;
public IntPtr pszText;
public int cchTextMax;
public int iImage;
public int lParam;
public int iIndent;
}
/// <summary>
/// Summary description for ListViewItem.
/// </summary>
public class ListViewItem
{
public ListViewItem()
{
}

public const int PROCESS_QUERY_I NFORMATION = 1024;
public const int PROCESS_VM_OPER ATION = 0x8;
public const int PROCESS_VM_READ = 0x10;
public const int PROCESS_VM_WRIT E = 0x20;
public const int STANDARD_RIGHTS _REQUIRED = 0xF0000;
public const int MAX_LVMSTRING = 255;
public const int MEM_COMMIT = 0x1000;
public const int MEM_RELEASE = 0x8000;
public const int PAGE_READWRITE = 0x4;
public const int LVIF_TEXT = 0x1;

private const int LVM_FIRST = 0x1000;
private const int LVM_GETITEMCOUN T = LVM_FIRST + 4;
private const int LVM_GETCOLUMN = LVM_FIRST + 25;
private const int LVM_GETITEM = LVM_FIRST + 5;
private const int LVM_GETITEMTEXT = 0x102D;

bool result;
IntPtr pHandle;
IntPtr pStrBufferMemor y;
IntPtr pMyItemMemory;

[DllImport("kern el32.dll")]
public static extern IntPtr OpenProcess(int dwDesiredAccess , bool
bInheritHandle, int dwProcId );
[DllImport("kern el32.dll")]
public static extern IntPtr VirtualAllocEx( IntPtr hProcess,IntPtr lpAddress,
int dwSize, int flAllocationTyp e, int flProtect );
[DllImport("kern el32.dll")]
public static extern bool VirtualFreeEx(I ntPtr hProcess, IntPtr lpAddress,
int dwSize, int dwFreeType);
[DllImport("kern el32.dll")]
public static extern bool WriteProcessMem ory(IntPtr hProcess, IntPtr
lpBaseAddress,r ef LV_ITEMA lpBuffer, int nSize, ref int
lpNumberOfBytes Written);
[DllImport("kern el32.dll")]
public static extern bool ReadProcessMemo ry(IntPtr hProcess, IntPtr
lpBaseAddress, ref LV_ITEMA lpBuffer, int nSize, ref int
lpNumberOfBytes Written);
[DllImport("user 32.dll")]
public static extern int SendMessage(Int Ptr hWnd, int Msg, int wParam,
IntPtr lParam);
[DllImport("kern el32.dll")]
public static extern bool CloseHandle(Int Ptr hObject);

public void Run(IntPtr ptr)
{
strBuffer = new byte[MAX_LVMSTRING];
Process [] localByName = Process.GetProc essesByName("my Process");
Process proc = localByName[0];
pHandle = OpenProcess(PRO CESS_VM_OPERATI ON | PROCESS_VM_READ |
PROCESS_VM_WRIT E, false, proc.Id);
pStrBufferMemor y = VirtualAllocEx( pHandle,IntPtr. Zero, MAX_LVMSTRING,
MEM_COMMIT, PAGE_READWRITE) ;
LV_ITEMA lv = new LV_ITEMA();
lv.mask = LVIF_TEXT;
lv.iItem = 1;
lv.iSubItem = 5;
lv.pszText = pStrBufferMemor y;
lv.cchTextMax = MAX_LVMSTRING;
pMyItemMemory = VirtualAllocEx( pHandle,IntPtr. Zero, Marshal.SizeOf( lv),
MEM_COMMIT, PAGE_READWRITE) ;
IntPtr lvptr = Marshal.AllocHG lobal(Marshal.S izeOf(lv));
Marshal.Structu reToPtr(lv,lvpt r,false);
int written = 0;
result = WriteProcessMem ory(pHandle, pMyItemMemory,r ef lv,
Marshal.SizeOf( lv), ref written);

int i = SendMessage(ptr , LVM_GETITEM, 0, pMyItemMemory);
i = SendMessage(ptr , LVM_GETITEMTEXT , 1, pStrBufferMemor y);
IntPtr ppr = IntPtr.Zero;
int read = 0;
StringBuilder str = new StringBuilder(M AX_LVMSTRING);
result = ReadProcessMemo ry(pHandle, pMyItemMemory,r ef lv, written,ref read);
string str1 = Marshal.PtrToSt ringAnsi(lv.psz Text);
}

As a result of i = SendMessage(ptr , LVM_GETITEMTEXT , 1, pStrBufferMemor y);
I'm receiving 0 - means false and
string str1 = Marshal.PtrToSt ringAnsi(lv.psz Text);
Gives me an error : Object instance not set to object.
Please help
Thanks in advance
brgds
Jacek
Jul 21 '05 #1
0 1909

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1435
by: thomas | last post by:
hi, i make a listview and add three items. the backgroundcolor of the listview is white and the textcolor ist black. on my notebook (IBM Thinkpad, XP Sp2) i cannnot see the items. on my pc (P4, Xp S2) i can see the items. regards Thomas
6
3400
by: Nick | last post by:
Hi there, I'm trying to implement drag-drop for my listview control in large icon view mode. Unfortunately the order of the items gets completely messed up upon inserting the item back into the listview, removing the item obviously keeps everything fine but the second I use insert the item is added to the *end* of the listview. Does anyone have any tips on how I can solve this issue?? Call Items.Remove(SourceItem)
0
428
by: Jacek | last post by:
Hi If it is wrong newsgroup, please let me know where to find the answer. I am trying to get item text form ListView (there are few items and 5 columns) from other application (application written in MFC). As I know I have to allocate memory in target application address space, send a message and than read from allocated memory. But I still doing something wrong and can't find correct solution. I fell I am close to it. Please find code...
1
5079
by: dvestal | last post by:
I have a ListView with checkboxes. I want to remove items when the checkboxes are unchecked, but to do so yields an ArgumentOutOfRangeException. Is there an easy way to get around this? A simple program that illustrates the exception is below: using System; using System.Windows.Forms; namespace WindowsApplication1
0
1886
by: Peter | last post by:
Hi, I have a problem with Listview using checkboxes. If i check items by code BEFORE the form is shown the Listview.Items are confused during the ItemChecked Event !!! After showing the form every thing works fine: checking items by code as well as checking with mouse: Using the CheckdItems Property is confused too.
2
6825
by: Peter | last post by:
Hi, I have a problem with Listview using checkboxes. If i check items by code BEFORE the form is shown the Listview.Items are confused during the ItemChecked Event !!! After showing the form every thing works fine: checking items by code
11
1460
by: Armin Zingler | last post by:
"Bill Schanks" <wschanks@gmail.comschrieb Try to execute lvMembers.beginupdate before filling and lvMembers.endupdate
1
8347
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
Hello, In my application I need to periodically remove all current items from a ListView and add a new set into it. The following abbreviated code contains the basic idea: private void FillListViewFromFile(string path) {
1
3787
by: prpradip | last post by:
In my application ListView is inside panel (XP theme enable), item text in the ListView control overlaps other items in small icon view. The items are drawn as if aligned to a grid and this causes items to be drawn in overlapped manner which obviosuly looks horrrible. I have tried to change allignment with no success. There is no problem regarding List and Details mode. What might be the problem?
0
8413
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8324
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8513
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6176
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2742
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1970
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1733
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.