Hi all,
As titled, I want to read text content from a standard syslistview32 control in an application. And the syslistview32 control is not a pop-up but embedded in the application, which means the control has same process ID as the application. In that case, I don't have to call VirtualAllocEx or WriteProcessMemory.
So far, I could successfully get syslistview32 control's handle, count how many items listed. But still can not read its content. Could you please tell me how to do it correctly?
require 'Win32API'
findwin = Win32API.new('user32', 'FindWindow', 'PP', 'L')
getdlg = Win32API.new('user32', 'GetDlgItem', 'LL', 'L')
sendmsg = Win32API.new('user32', 'SendMessage', 'LLLP', 'L')
#Some irrelevant details are ignored
#Here I've already got syslistview32 control's handle, let's assume it is resultslist = 3739380
puts "Count of items = #{sendmsg.call(resultslist, 4100, 0, nil)}" #LVM_GETITEMCOUNT = 0x1004
puts header = getdlg.call(resultslist, 0).to_s(16).upcase
#No problem, this works
#From here I tried to SendMessage with LVM_GETITEMTEXT parameter to get syslistview32's content
#Solution I: define a struct as described in MSDN, but something wrong when I tried to pack, this is due to my lack of knowledge on pack&unpack
LV_item = Struct.new(:mask, :iItem, :iSubItem, :state, :stateMask, :pszText, :cchTextMax, :iImage, :lParam)
lv_item = LV_item.new()
puts sendmsg.call(resultslist, 4165, 1, lv_item.to_a.pack("p"))
=> return value is 1, success?
puts lv_item.inspect
=> #<struct LV_item mask=nil, iItem=nil, iSubItem=nil, state=nil, stateMask=nil, pszText=nil, cchTextMax=nil, iImage=nil, lParam=nil> absolutely not succeed
#If I initiate lv_item = LV_item.new(0, 0, 0, 0, 0, "", 0, 0, ""), then error occurs at packing: can't convert Fixnum into String (TypeError). Can I pack integer pointer except pack("p")?
#Solution II: Directly pack an array and pass to SendMessage, return value is still nil
lv_item = [0, 0, 0, 0, 0, "\000", 0, 0, "\000"]
lv_item = lv_item.pack("IiiIIpiip")
puts sendmsg.call(resultslist, 4165, 1, lv_item)
=> return value is 1, success?
lv_item = lv_item.unpack("IiiIIpiip")
puts lv_item.inspect
=> [0, 0, 0, 0, 0, "\000", 0, 0, "\000"], nothing is padded actually
I really appreciate if you can answer my question, thanks in advance.
Have a good nite or morning/afternoon,
Thyrlian