flat assembler
Message board for the users of flat assembler.

Index > Windows > callback procedure

Author
Thread Post new topic Reply to topic
coconut



Joined: 02 Apr 2004
Posts: 326
Location: usa
coconut
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 Very Happy


Description:
Download
Filename: callback.zip
Filesize: 8.53 KB
Downloaded: 225 Time(s)

Post 11 May 2004, 06:09
View user's profile Send private message Reply with quote
decard



Joined: 11 Sep 2003
Posts: 1092
Location: Poland
decard
nice example Smile
You may also want to take a look at Fresh soueces. It also uses interesing method of handling windows messages (via MessageList macro).
Post 11 May 2004, 06:43
View user's profile Send private message Visit poster's website Reply with quote
coconut



Joined: 02 Apr 2004
Posts: 326
Location: usa
coconut
cant find the MessageList macro which file is it in? thanks
Post 13 May 2004, 00:23
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3502
Location: Bulgaria
JohnFound
coconut wrote:
cant find the MessageList macro which file is it in? thanks


in './include/libs/msgutils.inc'
You have to see also './include/libs/msgutils.asm' for JumpTo procedure.

Regards.
Post 13 May 2004, 08:00
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
roticv



Joined: 19 Jun 2003
Posts: 374
Location: Singapore
roticv
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
    
Post 13 May 2004, 08:13
View user's profile Send private message Visit poster's website MSN Messenger Reply with quote
coconut



Joined: 02 Apr 2004
Posts: 326
Location: usa
coconut
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
Post 13 May 2004, 18:34
View user's profile Send private message Reply with quote
roticv



Joined: 19 Jun 2003
Posts: 374
Location: Singapore
roticv
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.
Post 14 May 2004, 08:44
View user's profile Send private message Visit poster's website MSN Messenger Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
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.
Post 14 May 2004, 12:35
View user's profile Send private message Visit poster's website Reply with quote
pelaillo
Missing in inaction


Joined: 19 Jun 2003
Posts: 878
Location: Colombia
pelaillo
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]
    
Post 14 May 2004, 12:46
View user's profile Send private message Yahoo Messenger Reply with quote
coconut



Joined: 02 Apr 2004
Posts: 326
Location: usa
coconut
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?
Post 14 May 2004, 13:03
View user's profile Send private message Reply with quote
roticv



Joined: 19 Jun 2003
Posts: 374
Location: Singapore
roticv
pelaillo wrote:
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]
    


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.
Post 14 May 2004, 15:36
View user's profile Send private message Visit poster's website MSN Messenger Reply with quote
pelaillo
Missing in inaction


Joined: 19 Jun 2003
Posts: 878
Location: Colombia
pelaillo
Sorry, my fault. Sad I wrongly read ebp
Post 14 May 2004, 18:17
View user's profile Send private message Yahoo Messenger Reply with quote
coconut



Joined: 02 Apr 2004
Posts: 326
Location: usa
coconut
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?
Post 15 May 2004, 00:50
View user's profile Send private message Reply with quote
roticv



Joined: 19 Jun 2003
Posts: 374
Location: Singapore
roticv
Yes. You can even use parameters relative to esp, but it would be harder to work with.
Post 15 May 2004, 07:03
View user's profile Send private message Visit poster's website MSN Messenger Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.