Reputation: 2773
I'm trying to read the text of desktop icons using win32gui (I must use win32 because I also need to get the positions of the icons and they should match the text).
I used the code in here: Use Python to extract ListView items from another application and it returned a list with empty strings. I tried to check return codes and other values and they all make sense.
If the control is in the same process as your code, it should work. If it's in a different process (as "another application" suggests), then this doesn't work (or at least it shouldn't). Check the error codes, you should get something along the lines of "permission denied".
But the desktop is in a different process and I got no error codes!
To get the handle of the desktop window I used the get_desktop()
function that I posted in the solution section in here: How to get desktop item count in python?
Any ideas? Thanks!
Upvotes: 0
Views: 442
Reputation: 2773
I found the answer! It was the LVITEM
struct that was wrong.
The struct I used was for 32 bit architecture but my computer is 64 bit (the python is 32 bit but it doesn't matter).
This forum has the assembly answer. And here is a follow up question which contains the struct in python.
Basically, the stateMask
field has to be 64 bits long and all the pointers should also be 64 bits long (pszText
, puColumns
and piColFmt
) and also lParam
. I don't understand the why stateMask
should be 64 bit yet, but that's what the follow up question is for.
Upvotes: 1
Reputation: 18921
Here is an example of someone with the same problem, where the listview was in another process so it couldn't be read directly:
http://www.xiandg.com/2094118/codep1/get-text-of-lvitem-with-lvmgetitem-and-sendmessage-in-c
The answer:
Because the memory block that contains the text is owned by the other process, you will need to pull a few tricks to marshal the text from the process into your process.
That procedure is detailed here: http://taylorza.blogspot.com/2009/08/archive-hacking-my-way-across-process.html
Upvotes: 0