473,386 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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((IntPtr)mainWindowHwnd, IntPtr.Zero,
"ListView20WndClass", IntPtr.Zero);

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

int row_selected = SendMessage(lvwHwnd, (int)LVM_GETNEXTITEM,
-1,(IntPtr)1);
IntPtr pid = (IntPtr)0;
GetWindowThreadProcessId(lvwHwnd, ref pid);

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

IntPtr process = OpenProcess(PROCESS_VM_OPERATION |
PROCESS_VM_READ | PROCESS_VM_WRITE | PROCESS_QUERY_INFORMATION, 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 = WriteProcessMemory(process, _lvi, ref lvi,
Marshal.SizeOf(typeof(LVITEM)), IntPtr.Zero);

SendMessage(lvwHwnd, LVM_GETITEMTEXT, row_selected, _lvi);
//Error comes here
IntPtr bytesReaded;
ReadProcessMemory(process, _item, item, 512, out bytesReaded);

}
virtualFreeEx(process, _lvi, 0, MEM_RELEASE);
VirtualFreeEx(process, _item, 0, MEM_RELEASE);

}

In my specific application when I call
SendMessage(lvwHwnd, 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 5041
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((IntPtr)mainWindowHwnd, IntPtr.Zero,
"ListView20WndClass", IntPtr.Zero);

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

int row_selected = SendMessage(lvwHwnd, (int)LVM_GETNEXTITEM,
-1,(IntPtr)1);
IntPtr pid = (IntPtr)0;
GetWindowThreadProcessId(lvwHwnd, ref pid);

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

IntPtr process = OpenProcess(PROCESS_VM_OPERATION |
PROCESS_VM_READ | PROCESS_VM_WRITE | PROCESS_QUERY_INFORMATION, 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 = WriteProcessMemory(process, _lvi, ref lvi,
Marshal.SizeOf(typeof(LVITEM)), IntPtr.Zero);

SendMessage(lvwHwnd, LVM_GETITEMTEXT, row_selected, _lvi);
//Error comes here
IntPtr bytesReaded;
ReadProcessMemory(process, _item, item, 512, out bytesReaded);

}
virtualFreeEx(process, _lvi, 0, MEM_RELEASE);
VirtualFreeEx(process, _item, 0, MEM_RELEASE);

}

In my specific application when I call
SendMessage(lvwHwnd, 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((IntPtr)mainWindowHwnd, IntPtr.Zero,
"ListView20WndClass", IntPtr.Zero);

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

int row_selected = SendMessage(lvwHwnd, (int)LVM_GETNEXTITEM,
-1,(IntPtr)1);
IntPtr pid = (IntPtr)0;
GetWindowThreadProcessId(lvwHwnd, ref pid);

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

IntPtr process = OpenProcess(PROCESS_VM_OPERATION |
PROCESS_VM_READ | PROCESS_VM_WRITE | PROCESS_QUERY_INFORMATION, 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 = WriteProcessMemory(process, _lvi, ref lvi,
Marshal.SizeOf(typeof(LVITEM)), IntPtr.Zero);

SendMessage(lvwHwnd, LVM_GETITEMTEXT, row_selected, _lvi);
//Error comes here
IntPtr bytesReaded;
ReadProcessMemory(process, _item, item, 512, out bytesReaded);

}
virtualFreeEx(process, _lvi, 0, MEM_RELEASE);
VirtualFreeEx(process, _item, 0, MEM_RELEASE);

}

In my specific application when I call
SendMessage(lvwHwnd, 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
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
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...
2
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...
0
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...
2
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#. ...
6
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...
10
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...
4
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...
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.