Hello,
I can retrieve column text from a ListView in another process but I
cant figure out how to access to structure elements (LVCOLUMN)
<code>
//Handle variable is a valid ListView handle
LV_COLUMN ListViewItem = new LV_COLUMN();
IntPtr ListViewItemPoi nter = IntPtr.Zero;
byte[] ListViewItemBuf fer = new byte[512];
IntPtr ListViewPointer _item = IntPtr.Zero;
IntPtr ListViewProcess Pointer = IntPtr.Zero;
//open the process
int ProcessID;
Win32.GetWindow ThreadProcessId (Handle, out ProcessID);
ListViewProcess Pointer = Win32.OpenProce ss(Win32.PROCES S_VM_OPERATION
| Win32.PROCESS_V M_READ | Win32.PROCESS_V M_WRITE |
Win32.PROCESS_Q UERY_INFORMATIO N, false, (int)ProcessID) ;
//allocate memory
ListViewItemPoi nter = Win32.VirtualAl locEx(ListViewP rocessPointer,
IntPtr.Zero, Marshal.SizeOf( typeof(LV_COLUM N)), Win32.MEM_COMMI T,
Win32.PAGE_READ WRITE);
ListViewPointer _item = Win32.VirtualAl locEx(ListViewP rocessPointer,
IntPtr.Zero, 512, Win32.MEM_COMMI T, Win32.PAGE_READ WRITE);
//Get column Text (pszText) and width (cx)
int ColumnCnt=0;
bool GetColumnResult =true;
while (GetColumnResul t)
{
ListViewItem.ma sk=(int)Win32.L istViewConstant s.LVCF_TEXT|
(int)Win32.List ViewConstants.L VCF_WIDTH;
ListViewItem.cc hTextMax = 512;
ListViewItem.ps zText = ListViewPointer _item;
Win32.WriteProc essMemory(ListV iewProcessPoint er,
ListViewItemPoi nter,
ref ListViewItem, Marshal.SizeOf( typeof(LV_COLUM N)),
IntPtr.Zero);
GetColumnResult =Convert.ToBool ean((int)Win32. SendMessage(
Handle, (int)Win32.Wind owsMessages.LVM _GETCOLUMN,
(IntPtr)ColumnC nt, ListViewItemPoi nter));
if (GetColumnResul t)
{
IntPtr bytesReaded;
IntPtr buff = IntPtr.Zero;
Win32.ReadProce ssMemory(ListVi ewProcessPointe r,
ListViewPointer _item, ListViewItemBuf fer, 512, out bytesReaded);
MessageBox.Show ("ColumnText =["+Encoding.Unic ode.GetString(L istViewItemBuff er)
+"]");
MessageBox.Show ("ColumnWidt h (not
working)="+List ViewItem.cx.ToS tring());
}
ColumnCnt++;
}
Win32.VirtualFr eeEx(ListViewPr ocessPointer, ListViewItemPoi nter, 0,
Win32.MEM_RELEA SE);
Win32.VirtualFr eeEx(ListViewPr ocessPointer, ListViewPointer _item, 0,
Win32.MEM_RELEA SE);
</code:
QUESTIONS
***************
- How can I get my LVCOLUMN structure from memory to read the cv
member to get the column Width ?
- Unicode issue, When displaying the column name, look like there is
something to trim because the last "]" character is missing when
executing :
MessageBox.Show ("ColumnText =["+Encoding.Unic ode.GetString(L istViewItemBuff er)
+"]<-Text here is ignored why???"); Is anybody know the correct way
to trim the string?
I cant find an ugly workaround for the unicode issue but I really need
to get access to the LVCOLUMN elements....the width by example
LVCOLUMN.cx is suppose to contain the width of the column when using
the mask LVCF_WIDTH.
I'm working on this since a long time....please help me if you can.
Thanks.
I can retrieve column text from a ListView in another process but I
cant figure out how to access to structure elements (LVCOLUMN)
<code>
//Handle variable is a valid ListView handle
LV_COLUMN ListViewItem = new LV_COLUMN();
IntPtr ListViewItemPoi nter = IntPtr.Zero;
byte[] ListViewItemBuf fer = new byte[512];
IntPtr ListViewPointer _item = IntPtr.Zero;
IntPtr ListViewProcess Pointer = IntPtr.Zero;
//open the process
int ProcessID;
Win32.GetWindow ThreadProcessId (Handle, out ProcessID);
ListViewProcess Pointer = Win32.OpenProce ss(Win32.PROCES S_VM_OPERATION
| Win32.PROCESS_V M_READ | Win32.PROCESS_V M_WRITE |
Win32.PROCESS_Q UERY_INFORMATIO N, false, (int)ProcessID) ;
//allocate memory
ListViewItemPoi nter = Win32.VirtualAl locEx(ListViewP rocessPointer,
IntPtr.Zero, Marshal.SizeOf( typeof(LV_COLUM N)), Win32.MEM_COMMI T,
Win32.PAGE_READ WRITE);
ListViewPointer _item = Win32.VirtualAl locEx(ListViewP rocessPointer,
IntPtr.Zero, 512, Win32.MEM_COMMI T, Win32.PAGE_READ WRITE);
//Get column Text (pszText) and width (cx)
int ColumnCnt=0;
bool GetColumnResult =true;
while (GetColumnResul t)
{
ListViewItem.ma sk=(int)Win32.L istViewConstant s.LVCF_TEXT|
(int)Win32.List ViewConstants.L VCF_WIDTH;
ListViewItem.cc hTextMax = 512;
ListViewItem.ps zText = ListViewPointer _item;
Win32.WriteProc essMemory(ListV iewProcessPoint er,
ListViewItemPoi nter,
ref ListViewItem, Marshal.SizeOf( typeof(LV_COLUM N)),
IntPtr.Zero);
GetColumnResult =Convert.ToBool ean((int)Win32. SendMessage(
Handle, (int)Win32.Wind owsMessages.LVM _GETCOLUMN,
(IntPtr)ColumnC nt, ListViewItemPoi nter));
if (GetColumnResul t)
{
IntPtr bytesReaded;
IntPtr buff = IntPtr.Zero;
Win32.ReadProce ssMemory(ListVi ewProcessPointe r,
ListViewPointer _item, ListViewItemBuf fer, 512, out bytesReaded);
MessageBox.Show ("ColumnText =["+Encoding.Unic ode.GetString(L istViewItemBuff er)
+"]");
MessageBox.Show ("ColumnWidt h (not
working)="+List ViewItem.cx.ToS tring());
}
ColumnCnt++;
}
Win32.VirtualFr eeEx(ListViewPr ocessPointer, ListViewItemPoi nter, 0,
Win32.MEM_RELEA SE);
Win32.VirtualFr eeEx(ListViewPr ocessPointer, ListViewPointer _item, 0,
Win32.MEM_RELEA SE);
</code:
QUESTIONS
***************
- How can I get my LVCOLUMN structure from memory to read the cv
member to get the column Width ?
- Unicode issue, When displaying the column name, look like there is
something to trim because the last "]" character is missing when
executing :
MessageBox.Show ("ColumnText =["+Encoding.Unic ode.GetString(L istViewItemBuff er)
+"]<-Text here is ignored why???"); Is anybody know the correct way
to trim the string?
I cant find an ugly workaround for the unicode issue but I really need
to get access to the LVCOLUMN elements....the width by example
LVCOLUMN.cx is suppose to contain the width of the column when using
the mask LVCF_WIDTH.
I'm working on this since a long time....please help me if you can.
Thanks.
Comment