News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Peculiarity with invoke

Started by Roger, November 07, 2008, 10:43:32 PM

Previous topic - Next topic

Roger

Hi All,

The following code works:-

               mov eax, WS_CHILD+WS_VISIBLE
               invoke CreateWindowEx, 0, ADDR szSBclass, ADDR szReady, eax, \
                         0,0, 0,0, [hWnd], ID_STATUSBAR, [hInstance], 0


The following code does not work:-

               mov eax, WS_CHILD+WS_VISIBLE
               invoke CreateWindowEx, 0, ADDR szSBclass, ADDR szReady, WS_CHILD+WS_VISIBLE \
                         0,0, 0,0, [hWnd], ID_STATUSBAR, [hInstance], 0

Peculiarity
The only difference is whether the dwstyle parameter is immediate or in a register and I cannot see why this matters.

At run time the first makes a status bar. The second does not display a status bar and I assume one is not made because CreateWindewEx returns eax = NULL.

Assembly and linking were done by GoASm and GoLink and I examined both using GoBug.
The only difference in the stack state for both versions just prior to the API call was the value of [hWnd] and this is never the same for any time I run the prog.

I tried both methods using call rather than invoke and both worked.

Regards Roger



BogdanOntanu

At least in MASM  ADDR will do a hidden LEA and will trash EAX ...

Hence I do suggest that you use another register for the constants or avoid ADDR
Ambition is a lame excuse for the ones not brave enough to be lazy.
http://www.oby.ro

Roger

Hi Bogdan,

Quote from: BogdanOntanu on November 07, 2008, 11:20:47 PM
At least in MASM ADDR will do a hidden LEA and will trash EAX ...

Hence I do suggest that you use another register for the constants or avoid ADDR

The version using EAX is the one that worked.
GoAsm did a straight push immediate for ADDR so that wouldn't have been a problem anyway.


(Sorry if you read it the other way; I transposed the code snippets first time but I thought I had edited it before anyone read it.)


Regards Roger

donkey

You are missing a coma in the 2nd version (without EAX), just before the line continuation character
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

Roger

Hi Donkey,

Thank you for seeing the obvious. With 20-20 hindsight I can't think how I missed it so many times while trying different versions.

Regards Roger