flat assembler
Message board for the users of flat assembler.

Index > Windows > Dealing with WM_NOTIFY

Author
Thread Post new topic Reply to topic
MattDiesel



Joined: 31 Oct 2010
Posts: 34
Location: England
MattDiesel 24 Nov 2010, 21:27
First up, fantastic language. It is amazing how easy it is to learn and use. Only been using it a week, but it is awesome. I've used a lot of languages in my time, and it's a real credit to those who have contributed to fasm that I now rate it as one of my easier languages to learn.

I am using a listview, and want to get some of the even notifications. I've been programming at a higher level for a few years, so I know how to deal with the events. Right now I'm using this to get the code:

Code:
mov eax,[lparam]
mov eax,[eax+8] ; code is the third dword
cmp eax,LVN_*
je .dosomething    


And it works perfectly well. So the good news is, there is not a problem. However, I imagine that given what I've seen of the language there is a way to do this better. I thought I'd struck gold when I found the 'label' instruction, and I was really hoping that this would work:

Code:
label nm NMHDR at lparam    


but alas it was not so. Instead I found that I had to use a size operator rather than NMHDR (none of which are 12 bytes either). So my question is simple. Can I make a label for a structure starting from an address? That way I would be doing 'mov eax,[nm.code]' which looks a lot prettier (and when you think that I then have to work with much bigger structures like NM_LISTVIEW to get more details I'm not sure I want to keep counting bytes).

Mat
Post 24 Nov 2010, 21:27
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 25 Nov 2010, 00:14
Try one of these:

Code:
mov eax,[lparam] 
mov eax,[eax+NMHDR.code]
cmp eax,LVN_* 
    


Code:
mov eax,[lparam] 
cmp [eax+NMHDR.code],LVN_* 
    


FASM also has some "assume" macro (it does more/less what you want), but I never used it.

Yours "label nm NMHDR at lparam" doesn't make much sense. "label" directive can only define label at specified address, nothing else (no structure, no members, etc.)

What you probably want to do would be something like:
Code:
virtual at lparam
  nm NMHDR
end virtual
    


But that would be a bad mistake! "lparam" is defined as "label lparam at ebp+XX" (where XX is some constant number), but the NMHDR structure is not located at "ebp+XX". It is located at address pointed by dword at ebp+XX - eg. indirection. "lparam" is only a pointer to structure, not instance of structure.

Becuase of that, you need to load address of NMHDR structure from "lparam" first ("mov eax, dword [lparam]"), and only then access memory at that address ("[eax + NMHDR.something]", "[eax + 4]", etc.). Both can't be done in single instruction.
Post 25 Nov 2010, 00:14
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20445
Location: In your JS exploiting you and your system
revolution 25 Nov 2010, 00:27
vid wrote:
Both can't be done in single instruction.
This is the most important thing to understand. You are forced to use at least two instructions because x86 does not support double indirection.
Code:
cmp [ [lparam] + NMHDR.something],LVN_*    
Post 25 Nov 2010, 00:27
View user's profile Send private message Visit poster's website Reply with quote
MattDiesel



Joined: 31 Oct 2010
Posts: 34
Location: England
MattDiesel 25 Nov 2010, 10:37
Thats a great help, and makes it much easier. It's still not as easy as it possibly could be, but it's a good step forward. It solved the problem of having to count up the bytes when using the extended versions of the structure.

Revolution, are you implying that other architectures may support double indirection? I figured it was not possible to nest at all in asm (which is a bit of a pain when you only have so many gprs).

I'm not on my computer, so I'll have to run some tests when I get home. The main reason I want this is for using ptAction in NMITEMACTIVATE for NM_RCLICK, I want to use TrackPopupMenu with it (I tried it counting the bytes and ended up with the menu being in the bottom corner of the screen).

Thanks again,

Mat
Post 25 Nov 2010, 10:37
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20445
Location: In your JS exploiting you and your system
revolution 25 Nov 2010, 10:45
MattDiesel wrote:
Revolution, are you implying that other architectures may support double indirection?
Yes. Some of the old mainframe instruction sets used to have such an addressing mode. Although the ones I have personally dealt with did not support the constant offset part, just the double indirection (and even then only for loads and stores, not for arithmetic).
Post 25 Nov 2010, 10:45
View user's profile Send private message Visit poster's website Reply with quote
MattDiesel



Joined: 31 Oct 2010
Posts: 34
Location: England
MattDiesel 25 Nov 2010, 12:19
That's pretty interesting... Not that it's particularly relevant to me.
Post 25 Nov 2010, 12:19
View user's profile Send private message Send e-mail 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.