flat assembler
Message board for the users of flat assembler.
Index
> Windows > callback procedure |
Author |
|
coconut 11 May 2004, 06:09
fascinating example by jeremy gordon, author of goasm, on a clean and efficient callback procedure. this guy knows his stuff
there are a couple lines i marked with ;;; after the incorrect_msg label which puzzled me, im still unsure about the accuracy of the translation tho the example works. if anyone could elaborate more on this please do
|
|||||||||||
11 May 2004, 06:09 |
|
decard 11 May 2004, 06:43
nice example
You may also want to take a look at Fresh soueces. It also uses interesing method of handling windows messages (via MessageList macro). |
|||
11 May 2004, 06:43 |
|
coconut 13 May 2004, 00:23
cant find the MessageList macro which file is it in? thanks
|
|||
13 May 2004, 00:23 |
|
roticv 13 May 2004, 08:13
Code: window_proc: mov edx,message_table call handle_msg ret 10h handle_msg: push ebp mov ebp,[esp+10h] mov ecx,[edx] add edx,4 incorrect_msg: dec ecx ;ecx contain number of entries in the table. js defwndproc ;so if there is no more entries to compare with handle if with defwndproc cmp [edx+ecx*8],ebp jnz incorrect_msg mov ebp,esp push esp ebx edi esi add ebp,4 call dword [edx+ecx*8+4] pop esi edi ebx esp jnc nodefwndproc ;using carry flag to return whether there is an error or not, pops does not change carry flag. defwndproc: invoke DefWindowProc,[esp+18h],[esp+18h],[esp+18h],[esp+18h] nodefwndproc: pop ebp ret |
|||
13 May 2004, 08:13 |
|
coconut 13 May 2004, 18:34
thanks roticv. so when windows calls window_proc the hwnd, wmsg, wparam, and lparam are in what registers? i can sort of understand that the code compares the wmsg to the message_table, and 'calls' the appropriate label, but i dont see where you get all these values from
|
|||
13 May 2004, 18:34 |
|
roticv 14 May 2004, 08:44
hwnd, wmsg, wparam, and lparam are on the stack. You access it relative to the esp or ebp, though at some parts of the code ebp is used to store the msg.
|
|||
14 May 2004, 08:44 |
|
f0dder 14 May 2004, 12:35
The idea is okay - it's not the most efficient way of dispatching, but that hardly matters for a wndproc anyway. It's easy to manage, which counts a lot more in my opinion.
I'm not too fond of using global storage for paintstruct et cetera. Multithreading isn't really an issue, and 16 dword's are hardly the end of the world - I just prefer the stack for temporary variables, as that way they really *are* temporary. I have one real gripe with the code, though: the use of harcoded constants. That's bad kung-fu. |
|||
14 May 2004, 12:35 |
|
pelaillo 14 May 2004, 12:46
coconut, there is an error here:
Offset between params must be 4 bytes. Code: defwndproc: invoke DefWindowProc,[esp+18h],[esp+18h],[esp+18h],[esp+18h] |
|||
14 May 2004, 12:46 |
|
coconut 14 May 2004, 13:03
hmm, i didnt change anything during the translation as i dont really understand fully how it works. here is jeremy's code from his article:
Code: PUSH [ESP+18h],[ESP+18h],[ESP+18h],[ESP+18h] ;allowing for change of ESP CALL DefWindowProcA what changes should be made? also roticv, if the hwnd, wmsg, wp, lp are on the stack how would you access them, to check for example which out of 2 buttons were clicked? are they simply on the stack in reverse and you pop them off? |
|||
14 May 2004, 13:03 |
|
roticv 14 May 2004, 15:36
pelaillo wrote: coconut, there is an error here: Pushing a variable onto the stack adds 4 to the value in esp. So in short the code is correct. Coconut, you can make use of ebp as a relative position and make reference to the parameter via it. |
|||
14 May 2004, 15:36 |
|
pelaillo 14 May 2004, 18:17
Sorry, my fault. I wrongly read ebp
|
|||
14 May 2004, 18:17 |
|
coconut 15 May 2004, 00:50
oh i see it now in jeremy's article
Code: 6. The ADD EBP,4 just before the call to the function is to ensure that EBP points to the parameters the stack in the same way as if the window procedure had been entered normally. This is intended to ensure that the function will be compatible if called by an ordinary window procedure written in assembler, for example:- WndProc: PUSH EBP MOV EBP,ESP ;now [EBP+8]=hWnd,[EBP+0Ch]=uMsg,[EBP+10h]=wParam,[EBP+14h]=lParam in any of my labels/functions i can use that for the parameters eh? |
|||
15 May 2004, 00:50 |
|
roticv 15 May 2004, 07:03
Yes. You can even use parameters relative to esp, but it would be harder to work with.
|
|||
15 May 2004, 07:03 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.