Reading value of a StatusBar (wx) control

M

Michele Locati

Hi to everybody

I hope this is the right place to post this question.

I have a problem I can't solve by myself. Maybe someone here can help me...

I need to access the content of a status bar field of a running Windows
application (which makes use of wxWidgets). I've just the executable,
not the source code of it.

I'm parsing the HWNDs until I found one of class msctls_statusbar32
(STATUSCLASSNAME).

For this HWND (which corresponds to the statusbar):
- SB_GETUNICODEFORMAT returns TRUE
- SB_ISSIMPLE returns FALSE

Then I call
rc=SendMessage(hWnd, SB_GETPARTS, 0, 0)
which returns correclty the number of parts of the statusbar control.

Th problem araises when I want to retrieve the content of one of these
parts. Here's the steps I follow:

1) I determine the length of the part text:
nChars=SendMessageW(hWnd, SB_GETTEXTLENGTHW, 0, 0) & 0xFFFF;
(this is correct: it's the length of the text of the first statusbar part)

2) I allocate a buffer to hold the text
lChars=(WCHAR *)malloc((nChars+1)*sizeof(WCHAR));

3) And finally, I retrieve the text:
nChars=SendMessageW(hWnd, SB_GETTEXTW, 0, lChars) & 0xFFFF;
Here it comes the error. Windows says that the error "unhandled
exception" is in comctl32.dll (v5.82.2900.2180), at offset 00006600.
After showing up the message, the running application owning the status
bar ends. To verify it's not an error of buffer overflow, I tried to
allocate a bigger buffer than the one specified by SB_GETTEXTLENGTHW
(30,000 bytes), but the error is still there.
I've trie to do use the SendMessageA with GETTEXTLENGTHA and
SB_GETTEXTA, but the error happened again.

I'm using Windows XP Pro with SP2.

Anyone?
 
M

Michele Locati

Michele Locati ha scritto:
Hi to everybody

I hope this is the right place to post this question.

I have a problem I can't solve by myself. Maybe someone here can help me...

I need to access the content of a status bar field of a running Windows
application (which makes use of wxWidgets). I've just the executable,
not the source code of it.

I'm parsing the HWNDs until I found one of class msctls_statusbar32
(STATUSCLASSNAME).

For this HWND (which corresponds to the statusbar):
- SB_GETUNICODEFORMAT returns TRUE
- SB_ISSIMPLE returns FALSE

Then I call
rc=SendMessage(hWnd, SB_GETPARTS, 0, 0)
which returns correclty the number of parts of the statusbar control.

Th problem araises when I want to retrieve the content of one of these
parts. Here's the steps I follow:

1) I determine the length of the part text:
nChars=SendMessageW(hWnd, SB_GETTEXTLENGTHW, 0, 0) & 0xFFFF;
(this is correct: it's the length of the text of the first statusbar part)

2) I allocate a buffer to hold the text
lChars=(WCHAR *)malloc((nChars+1)*sizeof(WCHAR));

3) And finally, I retrieve the text:
nChars=SendMessageW(hWnd, SB_GETTEXTW, 0, lChars) & 0xFFFF;
Here it comes the error. Windows says that the error "unhandled
exception" is in comctl32.dll (v5.82.2900.2180), at offset 00006600.
After showing up the message, the running application owning the status
bar ends. To verify it's not an error of buffer overflow, I tried to
allocate a bigger buffer than the one specified by SB_GETTEXTLENGTHW
(30,000 bytes), but the error is still there.
I've trie to do use the SendMessageA with GETTEXTLENGTHA and
SB_GETTEXTA, but the error happened again.

I'm using Windows XP Pro with SP2.

Anyone?

Ok, I solved it finally. It was due to inter-process memory protection.
To be able to use shared memory between two processes I used the code
shown here (adapted from Visual Basic)
http://www.visualbasicforum.com/showthread.php?t=114019
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,691
Members
48,796
Latest member
Greg L.

Latest Threads

Top