News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

wsprint help

Started by Trope, April 01, 2005, 01:54:23 AM

Previous topic - Next topic

Trope

I have a ListBox with X amount of items in it.

I am trying to retrieve the number of items and append the number of items to the caption.

For example, if the program name is "Processes" I want the caption changed to "Processes 65" if there are 65 processes listed in the List Box control.

Here is my code snippet that is not working:



; Get the Count
PUSH 0                    ; /lParam
PUSH 0                                   ; |wParam
PUSH 18B                                 ; |Message = LB_GETCOUNT
PUSH 65                                  ; |ControlID = 65 (101.)
PUSH DWORD PTR SS:[EBP+8]                ; |hWnd
CALL CALL 00401358 ; \SendDlgItemMessageA
DEC EAX ; Subtract 1 ( 0 based index that's why )
PUSH DWORD PTR SS:[EBP+8] ; DLG Handle
CALL 405068 ; SetWindowTextA



I THINK it is crashing on the SetWindowTextA because of the number in EAX.

I think I need to use a wsprintf but I cannot find any tutorials on this.

I know I AM CLOSE. Any advice? Even if it's psuedocode to point me in the right direction.

Thanks,

Trope



Tedd

Yes, you're right.
You have to convert the number to a STRING first ::)
(wsprintf will do it - use "Processes: %lu" as the format string)

Pseudo pseudo code:

* SendDlgItemMessage: LB_GETCOUNT
* dec eax
* wsprintf(ADDR buff,ADDR format_string,eax)  ;(don't forget stack cleanup if you're not using invoke!)
* SetWindowText: ADDR buff
No snowflake in an avalanche feels responsible.

MichaelW


BOOL SetWindowText( HWND hWnd,
   LPCTSTR lpString
);



eschew obfuscation

Infro_X

invoke SendMessage,[hDlg],LB_GETCOUNT,0,0
invoke wsprintf,addr RecivingBuffer,addr format,eax
add esp,3*4   ;Because wsprintf doesn't addjust the stack before return, we must adjust the stack according to how many variables we pushed (and what size)
...
then depending on what you want to change, just pass (push) addr buffer as the lpString to be sent.

Mirno

If you use the MASM invoke macro, then you don't need to balance the stack yourself. In the MASM32 includes wsprinf is declared as C calling convention so invoke will automagically know how much to adjust the stack by (assuming you don't do something wierd like push x, invoke wsprintf...).

If you push & call manually, then you will need to balance the stack though.

Mirno