flat assembler
Message board for the users of flat assembler.

Index > Windows > Cast LPARAM to HMHDR

Author
Thread Post new topic Reply to topic
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
Hello fasm.net, I got a question here.

I want to capture a notification (TCN_SELCHANGE) event in Win32 code, as seen here http://msdn.microsoft.com/en-us/library/ms933405.aspx

To do so you have to cast LPARAM to NMHDR inorder to get the results.

In C++, its

Code:
case WM_NOTIFY:

switch( ((NMHDR*)lParam)->code  ){

case TCN_SELCHANGE: //Tab control selection has changed

...
etc

    


I was thinking if maybe its not possible I could just use a timer to check which tab is selected.

But I want to know how to cast for future reference.

How does casting work in ASM. if anyone has done it before or knows how to implement it in FASM. Please let me know.
Thanks.
Post 06 Dec 2010, 16:06
View user's profile Send private message Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler
You don't cast in assembly, you just treat you data as whatever you want it to be. It seems that in the case of WM_NOTIFY, lParam is a pointer. Just dereference it. Then to get the correct member of the structure, add its offset to the address.

Code:
mov eax,[lParam]
cmp [eax+code],TCN_SELCHANGE    

_________________
This is a block of text that can be added to posts you make.
Post 06 Dec 2010, 17:02
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
Thanks mindcooler you cooled my mind, however the code did not work.

When I clicked on another Tab it did not swtich to it. But I fixed it. All I did was XORed EAX between and it worked. But it wouldn't have worked without your help though, so thank you so much. Here's how I changed it.

Code:
 mov eax,[lparam]
 cmp [eax+NMHDR.code],TCN_SELCHANGE
 je  .change
 xor eax,eax                   ; I added this line
 jmp ._done
 .change:
 invoke MessageBox,[hwnd],'Tab selection has changed','Notice',MB_OK

._done:
 jmp .def
    


It seems like the data in EAX was not flushed from the previous section during the jump. But it works now. Thanks again, mindcooler,

You cooled my mind.lol
Post 08 Dec 2010, 03:05
View user's profile Send private message Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler
I don't see why you need to clear eax unless you return at .def.
Post 08 Dec 2010, 07:27
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number 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.

Powered by rwasa.