flat assembler
Message board for the users of flat assembler.

Index > Windows > SendDlgItemMessage strange behaviour?

Author
Thread Post new topic Reply to topic
fatygant



Joined: 12 Sep 2011
Posts: 30
Location: Poznan, Poland
fatygant 23 Jan 2018, 16:59
Hi there!

I can't figure it out on my own. I have a very simple structure defining Modbus connection:
Code:
struct MODBUSCONFIG
  bMode     db ?
  bVariant  db ?
            dw ?
  dwTimeout dd ?
ends    
In .data section I initialized it like this:
Code:
modbus_cfg MODBUSCONFIG 0,0,3000    
Then in WM_INITDIALOG message I want to select the first item in IDC_CONNECTION combo box:
Code:
 .wminitdialog:
        invoke          SendDlgItemMessage,[hDlg],IDC_CONNECTION,CB_ADDSTRING,0,rs232_master_txt
        invoke          SendDlgItemMessage,[hDlg],IDC_CONNECTION,CB_ADDSTRING,0,rs232_slave_txt
        invoke          SendDlgItemMessage,[hDlg],IDC_CONNECTION,CB_ADDSTRING,0,tcpip_master_txt
        invoke          SendDlgItemMessage,[hDlg],IDC_CONNECTION,CB_ADDSTRING,0,tcpip_slave_txt
        ; connection settings
        invoke          SendDlgItemMessage,[hDlg],IDC_CONNECTION,CB_SETCURSEL,dword[modbus_cfg.bVariant],0    
And it does not work - the combo box appears with no selection.

However something like this works perfectly:
Code:
.wminitdialog:
        invoke          SendDlgItemMessage,[hDlg],IDC_CONNECTION,CB_ADDSTRING,0,rs232_master_txt
        invoke          SendDlgItemMessage,[hDlg],IDC_CONNECTION,CB_ADDSTRING,0,rs232_slave_txt
        invoke          SendDlgItemMessage,[hDlg],IDC_CONNECTION,CB_ADDSTRING,0,tcpip_master_txt
        invoke          SendDlgItemMessage,[hDlg],IDC_CONNECTION,CB_ADDSTRING,0,tcpip_slave_txt
        ; connection settings
        mov             al,[modbus_cfg.bVariant]
        invoke          SendDlgItemMessage,[hDlg],IDC_CONNECTION,CB_SETCURSEL,eax,0    
Why?! Does it have something to do with 'invoke' internals?

Thanks for your explanations!
Post 23 Jan 2018, 16:59
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20632
Location: In your JS exploiting you and your system
revolution 23 Jan 2018, 17:21
You have to consider the upper bits of the value.

When you load al the upper bits of eax come from the result of the previous SendDlgItemMessage call. But when you use the dword from the memory location the upper bits come from the timeout value.

Try this:
Code:
movzx eax,[modbus_cfg.bVariant] ;ensure all 32-bits are properly defined    
Also, it is a good idea to check the return value for each call, that can tell you what went wrong.
Post 23 Jan 2018, 17:21
View user's profile Send private message Visit poster's website Reply with quote
fatygant



Joined: 12 Sep 2011
Posts: 30
Location: Poznan, Poland
fatygant 23 Jan 2018, 19:49
Yes, but
Code:
mov al,[modbus_cfg.bVariant]    
followed by
Code:
SendDlgItemMessage,[hDlg],IDC_CONNECTION,CB_SETCURSEL,eax,0    
actually works... the version which is more straightforward (in my opinion) does not:
Code:
SendDlgItemMessage,[hDlg],IDC_CONNECTION,CB_SETCURSEL,dword[modbus_cfg.bVariant],0    

I will check the error code - I should have started with that Wink
Post 23 Jan 2018, 19:49
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20632
Location: In your JS exploiting you and your system
revolution 23 Jan 2018, 19:54
For the first "working" code, you are sending a full 32-bit value (eax) to SendDlgItemMessage, but only 8 of those bits came from modbus_cfg.bVariant, the other 24 bits came from whatever was in eax before. It is only "working" because the return value from SendDlgItemMessage leaves eax with the higher 24-bits as zero.

The second fails because you load the entire dword from memory, but some of those bits are from outside the single byte you wanted and contain other non-zero values in the higher 24 bits.
Post 23 Jan 2018, 19:54
View user's profile Send private message Visit poster's website Reply with quote
fatygant



Joined: 12 Sep 2011
Posts: 30
Location: Poznan, Poland
fatygant 24 Jan 2018, 09:48
revolution, thank you! It looks I still have a problem with very basic concepts...
Post 24 Jan 2018, 09:48
View user's profile Send private message 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.