News:

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

Re: InitCommonControlsEx() test on memory dialog.

Started by dedndave, March 19, 2011, 06:40:55 AM

Previous topic - Next topic

dedndave

15 bytes   :bg
ICC_FLAGS = ICC_WIN95_CLASSES
;comment out the ones you do not want
ICC_FLAGS = ICC_FLAGS or ICC_ANIMATE_CLASS
ICC_FLAGS = ICC_FLAGS or ICC_BAR_CLASSES
ICC_FLAGS = ICC_FLAGS or ICC_COOL_CLASSES
ICC_FLAGS = ICC_FLAGS or ICC_DATE_CLASSES
ICC_FLAGS = ICC_FLAGS or ICC_HOTKEY_CLASS
ICC_FLAGS = ICC_FLAGS or ICC_INTERNET_CLASSES
ICC_FLAGS = ICC_FLAGS or ICC_LISTVIEW_CLASSES
ICC_FLAGS = ICC_FLAGS or ICC_PAGESCROLLER_CLASS
ICC_FLAGS = ICC_FLAGS or ICC_PROGRESS_CLASS
ICC_FLAGS = ICC_FLAGS or ICC_TAB_CLASSES
ICC_FLAGS = ICC_FLAGS or ICC_TREEVIEW_CLASSES
ICC_FLAGS = ICC_FLAGS or ICC_UPDOWN_CLASS
ICC_FLAGS = ICC_FLAGS or ICC_USEREX_CLASSES

push ICC_FLAGS
push sizeof INITCOMMONCONTROLSEX
invoke InitCommonControlsEx,esp
pop ecx
pop edx

jj2007

Quote from: dedndave on March 19, 2011, 08:09:50 AM
you don't wanna suck all the fun out of it   :P

15  :U
:cheekygreen:

One more piece of awfully optimised non-maintainable code:
Quote   push edx
   mov edx, esp   ; shorter because it avoids a global variable
   invoke
WriteFile, hWrite, edi, eax, edx, 0   ; invoke WriteFile, hWrite, bufStart, bufCt, ptrBytesRead, 0
   pop eax   ; contains bytes written
[/color]

dedndave

that's an old one Jochen - lol
you should see my os info program   :P

here is a sample   :bg  just to make Hutch's day
the comments have been intentionally removed  - lol
        pushad
        jmp short mLoop1

mLoop0: INVOKE  TranslateMessage,esp
        INVOKE  DispatchMessage,esp

mLoop1: mov     eax,esp
        INVOKE  GetMessage,eax,edi,edi,edi
        neg     eax
        shr     eax,1
        jnz     mLoop0

        pop     eax
        JMP     ExitProcess

dedndave

how 'bout this one....
instead of
        INVOKE  DefWindowProc,hWnd,uMsg,wParam,lParam
        ret

do this...
        leave
        JMP     DefWindowProc

(hint: the RETurn address and 4 parms are already on the stack)

can't seem to get a rise out of Hutch, today
must be "Blondes on Bikes Day" in Oz   :bg

jj2007

Quote from: dedndave on March 19, 2011, 09:19:17 PM
        leave
        JMP     DefWindowProc


Cute, but don't forget the proc uses esi edi ebx :bg

dedndave

mine doesn't   :bg
and - if you do - do so manually so that you can pop them in the right order

jj2007

Can you imagine how much pushin' & poppin' can be avoided that way... and it's faster, too :green2

dedndave

not sure about speed - but count the bytes
another thing i managed to do was to use the same code for horz and vert scroll
also, rather than creating the main menu in resource, i have it in 64 bytes of code and 330 bytes of data
those are probably the biggest space savers
oh - i use a loop to create all my child windows   :P

jj2007

Quote from: dedndave on March 19, 2011, 09:49:02 PM
not sure about speed

Hey, three or four cycles less is an eternity, especially if you jump to DefWindowProc :green

By the way, I just sent some photos to a friend. Thunderbird needs about one minute per 1.2MB, say: 20000 bytes per second. And I really mean needs because the CPU is at 80%, and TB is the culprit...

CPU has 1.6GHz = 1600000000 cycles/second
Sending speed = 20000 bytes/second

Cycles per byte sent: 1600000000/20000=80000

Congrats to the C++ World :U

Quote from: dedndave on March 19, 2011, 09:49:02 PM
oh - i use a loop to create all my child windows   :P

Haha, the old stosd trick :green2

donkey

15 btyes also:

00401000 >/$ 66:68 FF03     PUSH 3FF
00401004  |. 6A 08          PUSH 8
00401006  |. 54             PUSH ESP                                 ; /pInitEx
00401007  |. E8 80510000    CALL <JMP.&COMCTL32.InitCommonControlsEx>; \InitCommonControlsEx
0040100C  |. 83C4 06        ADD ESP,6


pushw 03FFh ; all classes
push 8 ; size
invoke InitCommonControlsEx,esp
add esp,6
"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

dedndave

add esp,6 ????   :bg
not sure that PUSHW is legal

replace that with POP ECX, POP DX and you have it in 14, Edgar   :P

donkey

Hey Dave,

pop DX requires a 66h override in 32 bit mode:

66:5A

So its still 15 bytes, but yes, half stack operations should be perfectly legal. I haven't looked at the state of the stack after the pushw, it could be that the high word has garbage in it.
"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

Antariy

Quote from: donkey on March 20, 2011, 01:19:49 AM
Hey Dave,

pop DX requires a 66h override in 32 bit mode:

66:5A

So its still 15 bytes, but yes, half stack operations should be perfectly legal. I haven't looked at the state of the stack after the pushw, it could be that the high word has garbage in it.

No, calling API with unaligned stack is dangerous. If *planned* exception will occur, then SEH will not work - program will have terminated abnormally.
Also it will cause unexcepted behaviours of the API (even if it will not crash).

Try this code:

.nolist
include \masm32\include\masm32rt.inc
.686
.xmm
.code
start:
add esp,-2
invoke MessageBox,0,CTXT("Hello"),CTXT("Hi"),MB_ICONINFORMATION
pop ax
invoke ExitProcess,eax
end start


This is the image what I get on XP SP2 (crazy behaviour of MessageBox with unaligned stack):




dedndave

yah - that also violates the definition of the INITCOMMONCONTROLSEX structure
it wants to see 2 dwords - although - the upper 16 bits may be ignored
they may use them in the future, i suppose

Antariy

Quote from: dedndave on March 20, 2011, 02:31:56 AM
yah - that also violates the definition of the INITCOMMONCONTROLSEX structure
it wants to see 2 dwords - although - the upper 16 bits may be ignored
they may use them in the future, i suppose

Try to compile app in my previous post. What do you get?