473,776 Members | 1,503 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

External listview control memory exception when sendmessage is cal

Hello,

It may be a repeated question but I don't find the solution to the situation
that I encounter in it.
My application is monitoring another application that is built in VB6. The
application monitors all the textboxes and other input & display controls on
that application.
The data from the textboxes and listboxes are retrived fine. But, when it
comes to Listview there I got memory exception.
I know that I need to do the in memory processing with the external listview
control by hack into the process.
I have successfuly do the external listview like Task Manager and my own
dummy appilcation that has the Listview control and I am getting data from
rows in it.
But when it comes to this specific application I am getting the memory
exception.

Below is the code that successfully get external listview code from listview
control.

IntPtr mainWindowHwnd;
IntPtr lvwHwnd = (IntPtr)0;

try
{
mainWindowHwnd = FindWindow(null , null);

lvwHwnd = FindWindowEx((I ntPtr)mainWindo wHwnd, IntPtr.Zero,
"ListView20WndC lass", IntPtr.Zero);

if (lvwHwnd == (IntPtr)0)
throw new Win32Exception( );
}
catch (Exception ex)
{
MessageBox.Show (ex.Message);
return;
}

int row_selected = SendMessage(lvw Hwnd, (int)LVM_GETNEX TITEM,
-1,(IntPtr)1);
IntPtr pid = (IntPtr)0;
GetWindowThread ProcessId(lvwHw nd, ref pid);

IntPtr _lvi,_item;
IntPtr _subitem = IntPtr.Zero;

IntPtr process = OpenProcess(PRO CESS_VM_OPERATI ON |
PROCESS_VM_READ | PROCESS_VM_WRIT E | PROCESS_QUERY_I NFORMATION, false,
pid.ToInt32());

LVITEM lvi = new LVITEM();
_lvi = VirtualAllocEx( process, IntPtr.Zero,
Marshal.SizeOf( typeof(LVITEM)) , MEM_COMMIT, PAGE_READWRITE) ;
_item = VirtualAllocEx( process, IntPtr.Zero, 512, MEM_COMMIT,
PAGE_READWRITE) ;

if (_lvi == IntPtr.Zero)
throw new SystemException ("Failed to allocate memory in
remote process");

bool bsuccess;

lvi.cchTextMax = 512;
for (int j = 0; j <=10; j++)
{

lvi.iSubItem = j;
lvi.pszText = _item;
bsuccess = WriteProcessMem ory(process, _lvi, ref lvi,
Marshal.SizeOf( typeof(LVITEM)) , IntPtr.Zero);

SendMessage(lvw Hwnd, LVM_GETITEMTEXT , row_selected, _lvi);
//Error comes here
IntPtr bytesReaded;
ReadProcessMemo ry(process, _item, item, 512, out bytesReaded);

}
virtualFreeEx(p rocess, _lvi, 0, MEM_RELEASE);
VirtualFreeEx(p rocess, _item, 0, MEM_RELEASE);

}

In my specific application when I call
SendMessage(lvw Hwnd, LVM_GETITEMTEXT , row_selected, _lvi); //Error comes here
it crashes the other application.

What is wrong that I am doing? I have also check the user rights to run the
application and it is Administrator.

Anyone can suggest me the proper memory management or any other way to
handle this.

Thanks,
Irfan
Mar 30 '07 #1
2 5064
Hello,

Any update on this issue from anyone? Where are the experts?

One more thing to add, this particular problem occurs on a system that I am
running through terminal server. Is there some kind of rights issue? That
particular user is part of administrator group.
What kind of settings do I require here?

Thanks,
Irfan

"Irfan" wrote:
Hello,

It may be a repeated question but I don't find the solution to the situation
that I encounter in it.
My application is monitoring another application that is built in VB6. The
application monitors all the textboxes and other input & display controls on
that application.
The data from the textboxes and listboxes are retrived fine. But, when it
comes to Listview there I got memory exception.
I know that I need to do the in memory processing with the external listview
control by hack into the process.
I have successfuly do the external listview like Task Manager and my own
dummy appilcation that has the Listview control and I am getting data from
rows in it.
But when it comes to this specific application I am getting the memory
exception.

Below is the code that successfully get external listview code from listview
control.

IntPtr mainWindowHwnd;
IntPtr lvwHwnd = (IntPtr)0;

try
{
mainWindowHwnd = FindWindow(null , null);

lvwHwnd = FindWindowEx((I ntPtr)mainWindo wHwnd, IntPtr.Zero,
"ListView20WndC lass", IntPtr.Zero);

if (lvwHwnd == (IntPtr)0)
throw new Win32Exception( );
}
catch (Exception ex)
{
MessageBox.Show (ex.Message);
return;
}

int row_selected = SendMessage(lvw Hwnd, (int)LVM_GETNEX TITEM,
-1,(IntPtr)1);
IntPtr pid = (IntPtr)0;
GetWindowThread ProcessId(lvwHw nd, ref pid);

IntPtr _lvi,_item;
IntPtr _subitem = IntPtr.Zero;

IntPtr process = OpenProcess(PRO CESS_VM_OPERATI ON |
PROCESS_VM_READ | PROCESS_VM_WRIT E | PROCESS_QUERY_I NFORMATION, false,
pid.ToInt32());

LVITEM lvi = new LVITEM();
_lvi = VirtualAllocEx( process, IntPtr.Zero,
Marshal.SizeOf( typeof(LVITEM)) , MEM_COMMIT, PAGE_READWRITE) ;
_item = VirtualAllocEx( process, IntPtr.Zero, 512, MEM_COMMIT,
PAGE_READWRITE) ;

if (_lvi == IntPtr.Zero)
throw new SystemException ("Failed to allocate memory in
remote process");

bool bsuccess;

lvi.cchTextMax = 512;
for (int j = 0; j <=10; j++)
{

lvi.iSubItem = j;
lvi.pszText = _item;
bsuccess = WriteProcessMem ory(process, _lvi, ref lvi,
Marshal.SizeOf( typeof(LVITEM)) , IntPtr.Zero);

SendMessage(lvw Hwnd, LVM_GETITEMTEXT , row_selected, _lvi);
//Error comes here
IntPtr bytesReaded;
ReadProcessMemo ry(process, _item, item, 512, out bytesReaded);

}
virtualFreeEx(p rocess, _lvi, 0, MEM_RELEASE);
VirtualFreeEx(p rocess, _item, 0, MEM_RELEASE);

}

In my specific application when I call
SendMessage(lvw Hwnd, LVM_GETITEMTEXT , row_selected, _lvi); //Error comes here
it crashes the other application.

What is wrong that I am doing? I have also check the user rights to run the
application and it is Administrator.

Anyone can suggest me the proper memory management or any other way to
handle this.

Thanks,
Irfan
Apr 2 '07 #2
Hello,

Someone suggested to increase the _lvi (LVITEM) type memory but it did work.

_lvi = VirtualAllocEx( process, IntPtr.Zero, Marshal.SizeOf( typeof(LVITEM)) ,
MEM_COMMIT, PAGE_READWRITE) ;

I tried it to 255 but no luck.
_lvi = VirtualAllocEx( process, IntPtr.Zero, 255, MEM_COMMIT, PAGE_READWRITE) ;

Please advice on this. I need solution really urgent.
Thank you for your corporation.
Irfan

"Irfan" wrote:
Hello,

Any update on this issue from anyone? Where are the experts?

One more thing to add, this particular problem occurs on a system that I am
running through terminal server. Is there some kind of rights issue? That
particular user is part of administrator group.
What kind of settings do I require here?

Thanks,
Irfan

"Irfan" wrote:
Hello,

It may be a repeated question but I don't find the solution to the situation
that I encounter in it.
My application is monitoring another application that is built in VB6. The
application monitors all the textboxes and other input & display controls on
that application.
The data from the textboxes and listboxes are retrived fine. But, when it
comes to Listview there I got memory exception.
I know that I need to do the in memory processing with the external listview
control by hack into the process.
I have successfuly do the external listview like Task Manager and my own
dummy appilcation that has the Listview control and I am getting data from
rows in it.
But when it comes to this specific application I am getting the memory
exception.

Below is the code that successfully get external listview code from listview
control.

IntPtr mainWindowHwnd;
IntPtr lvwHwnd = (IntPtr)0;

try
{
mainWindowHwnd = FindWindow(null , null);

lvwHwnd = FindWindowEx((I ntPtr)mainWindo wHwnd, IntPtr.Zero,
"ListView20WndC lass", IntPtr.Zero);

if (lvwHwnd == (IntPtr)0)
throw new Win32Exception( );
}
catch (Exception ex)
{
MessageBox.Show (ex.Message);
return;
}

int row_selected = SendMessage(lvw Hwnd, (int)LVM_GETNEX TITEM,
-1,(IntPtr)1);
IntPtr pid = (IntPtr)0;
GetWindowThread ProcessId(lvwHw nd, ref pid);

IntPtr _lvi,_item;
IntPtr _subitem = IntPtr.Zero;

IntPtr process = OpenProcess(PRO CESS_VM_OPERATI ON |
PROCESS_VM_READ | PROCESS_VM_WRIT E | PROCESS_QUERY_I NFORMATION, false,
pid.ToInt32());

LVITEM lvi = new LVITEM();
_lvi = VirtualAllocEx( process, IntPtr.Zero,
Marshal.SizeOf( typeof(LVITEM)) , MEM_COMMIT, PAGE_READWRITE) ;
_item = VirtualAllocEx( process, IntPtr.Zero, 512, MEM_COMMIT,
PAGE_READWRITE) ;

if (_lvi == IntPtr.Zero)
throw new SystemException ("Failed to allocate memory in
remote process");

bool bsuccess;

lvi.cchTextMax = 512;
for (int j = 0; j <=10; j++)
{

lvi.iSubItem = j;
lvi.pszText = _item;
bsuccess = WriteProcessMem ory(process, _lvi, ref lvi,
Marshal.SizeOf( typeof(LVITEM)) , IntPtr.Zero);

SendMessage(lvw Hwnd, LVM_GETITEMTEXT , row_selected, _lvi);
//Error comes here
IntPtr bytesReaded;
ReadProcessMemo ry(process, _item, item, 512, out bytesReaded);

}
virtualFreeEx(p rocess, _lvi, 0, MEM_RELEASE);
VirtualFreeEx(p rocess, _item, 0, MEM_RELEASE);

}

In my specific application when I call
SendMessage(lvw Hwnd, LVM_GETITEMTEXT , row_selected, _lvi); //Error comes here
it crashes the other application.

What is wrong that I am doing? I have also check the user rights to run the
application and it is Administrator.

Anyone can suggest me the proper memory management or any other way to
handle this.

Thanks,
Irfan
Apr 5 '07 #3

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

Similar topics

2
21266
by: John Lauwers | last post by:
I know you can edit the first column of the listview control, is there a way to edit the second and/or the other columns? greets John
8
22324
by: Jon Ripley | last post by:
Using VB6 (for two weeks!) I could get a ListBox search working perfectly but with a ListView it has completely stumped me. I've not found any previous posts that have helped :( The user enters a string into a text box (txtStreet) and as they type any matching entry in the listview (lsvStreets) is highlighted and made visible. The search highlights the first item starting with the text in txtStreet. The listview contains 6,000 rows...
2
4736
by: Anushya devi | last post by:
Hi All I used listview and tried to update it by using Addrange. When the number of items is less, it works fine.. But I need to update nearly 200,000 items and it hangs. Also i need to add images to listview also(This is to list all the items in my inbox, and want to give the user the feel of outlook). Since it hangs for even 1000 items in the inbox, i tried to shift to virtual listview. But virtual listview
0
4499
by: cyrille | last post by:
Hello from example from web i did a little code to avoiding columnHeader resize. this code seems to work well, but when I put a 'normal' ListView on the same Form than my overrided ListView it seems to stop working. if I'm resizing 'normal' ListView ColumnHeaders, then I can resizing ColumnHeaders of my overrided ListView. If I don't resizing 'normal' ListView ColumnHeaders, then resizing of my overrided ListView ColumnHeaders is...
2
12530
by: Gary Brown | last post by:
Hi, How do you programmatically scroll a ListView control horizontally? (The same effect as if the user used the horizontal scroll bar,) I've done it in C++/MFC, but can't find the means in C#. Autoscroll is enabled. Also, I need to know if the user scrolls the ListView horizontally. Thanks,
6
5039
by: Jack | last post by:
Hello, I've noticed through searching this group's previous posts that one can get the item the mouse is over in a listview control but I did not see how to get the subitem the mouse is over. Is this possible? I intend on replacing an ActiveX grid with a listview control from a VB6 application that I've upgraded to VB .NET. The existing functionlality uses the mouseover event of the grid to display specific information within...
10
12309
by: Adam Honek | last post by:
This is probably a silly question but oh well, I can't find the answer looking via code. Having an imagelist already, how does one set an icon for a list view's sub items? I'm using the code below however the subitems doesn't have an overload allowing an image index. Adam
4
5595
by: Steve | last post by:
Hi all, I don't want to use the datagrid if I don't have to. Is there a way to setup a ListBox to have more than one checkbox column? I need something like this | Include || Set as Default || Other columns... | asdasdasd digity-digity!
2
6176
by: witpo | last post by:
Hi, I would like to display all listview items in one row with scroll bar below it – instead of multiple rows and scroll bar on the right. Someone told me that I can achieve it using LVM_SETITEMPOSITION message. According to my knowledge code below should set position for each item added to listView control. There are two ways of doing it - we can use MessageWindow.SendMessage from Microsoft.WindowsCE.Forms or use DllImport and SendMessage....
0
9628
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
10289
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10061
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,...
0
8952
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6722
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5367
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
5493
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3622
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2860
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.