HI!
I've been trying to "shrink" Iczelions?s Simple window example, and this is what I got.
Can anybody tell me why it doesn?t seem to work properly?

Attached code:


;

.386
.model flat,stdcall
OPTION casemap:none

;
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib

;
;-------------
; MACROS
;-------------

salir MACRO arg
mov eax, arg
ret
ENDM

;
;=================
; Local prototypes
;=================

WinMain PROTO :DWORD, :DWORD, :DWORD, :DWORD

.data
ClassName DB "ClaseUno",0
Caption1 DB "Primera Ventana",0
.code

start:
invoke WinMain, 40000, NULL, NULL, SW_SHOWDEFAULT
invoke ExitProcess, NULL

WinMain PROC hInst:DWORD, hPrevInst:DWORD, CmdLine:DWORD, CmdShow:DWORD
LOCAL wc :WNDCLASSEX <sizeof WNDCLASSEX, CS_HREDRAW or CS_VREDRAW or CS_BYTEALIGNWINDOW\
,offset WndProc, 0, 0, 400000, 0, 0, COLOR_BTNFACE + 1, 0, addr ClassName, 0>
;Variables locales para usarlas mediante el stack

invoke RegisterClassEx, addr wc
invoke CreateWindowEx, NULL, addr ClassName, addr Caption1, WS_VISIBLE, NULL,NULL,400000,NULL
LOCAL hWnd1 :DWORD
invoke UpdateWindow
LOCAL msg :MSG

.WHILE TRUE ;Main Event Loop
invoke GetMessage, addr msg, hWnd1,0,0
.BREAK .IF (!eax) ;Para si no hay mensajes
invoke TranslateMessage, addr msg
invoke DispatchMessage, addr msg

.ENDW
ret
WinMain ENDP


WndProc PROC hWnd:DWORD, idMsg:DWORD, wParam:DWORD, lParam:DWORD
;Called by DispatchMessage only

.IF idMsg==WM_DESTROY
invoke PostQuitMessage, NULL
.ELSE
invoke DefWindowProc, hWnd, idMsg, wParam, lParam
;Le pasa los mismos par?metros a Default...
ret
.ENDIF
salir 0 ;Sale sin errores

WndProc ENDP

END start



Posted on 2002-07-15 05:39:11 by slop
The three most glaring errors:

- you are missing a parameter with your call to UpdateWindow, you need to specify an hWnd

- there is not RET at the end of your WndProc

- you never move a value into hWnd1, so when you call GetMessage there is an unknown value in there


I know that you are a newbie, but that is pretty sloppy coding. You just need to take more care, and errors like this won't happen ;) :cool:

Posted on 2002-07-15 07:01:42 by sluggy
You've presumed an hInstance, which is a bad thingTM.... Not only that, but you've presumed the wrong one!

It may look right, but thats because you've forgoten the magic character.

Mirno
Posted on 2002-07-15 07:07:56 by Mirno

You've presumed an hInstance, which is a bad thingTM.... Not only that, but you've presumed the wrong one!

It may look right, but thats because you've forgoten the magic character.

Mirno


And a 0 :)



invoke WinMain, 400000h, 0, 0, SW_SHOWDEFAULT


It's not a "bad thing" (TM). You know, we already had a discussion about that :)

Here is an example source, generated by my "FRM2ASM" tool,
wich should be something like the "minimum" Window ;)
(notice that it also centers the window :rolleyes: )



.486
.model flat, stdcall
option casemap :none

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib

.data


szClassName db "Form1", 0

wc WNDCLASSEX <sizeof wc, CS_HREDRAW \
or CS_VREDRAW or CS_BYTEALIGNWINDOW, \
offset WndProc, 0, 0, 400000h, \
0, 0, COLOR_BTNFACE + 1, 0, \
offset szClassName, 0>

szForm1 db "Form1", 0

.data?
hWnd dd ?
msg MSG <?>

.code

start:

call WinMain
invoke ExitProcess, eax

WinMain proc
mov wc.hIcon, 0
invoke LoadCursor, 0, IDC_ARROW
mov wc.hCursor, eax
invoke RegisterClassEx, addr wc
invoke GetSystemMetrics, SM_CXSCREEN
mov esi,eax
invoke GetSystemMetrics, SM_CYSCREEN
shr esi, 1
shr eax, 1
sub eax, 394/2
sub esi, 228/2

invoke CreateWindowEx, WS_EX_TOPMOST,
addr szClassName,
addr szForm1,
WS_CAPTION or WS_MINIMIZEBOX or WS_SYSMENU or WS_VISIBLE,
esi, eax, 394, 228, 0, 0, 400000h, 0
mov hWnd, eax
invoke ShowWindow, hWnd, SW_SHOWNORMAL
invoke UpdateWindow, hWnd
mov esi, offset msg
@@:
invoke GetMessage, esi, 0, 0, 0
or eax, eax
je @F
invoke TranslateMessage, esi
invoke DispatchMessage, esi
jmp @B
@@:
mov eax, msg.wParam
ret
WinMain endp

WndProc proc hWin :DWORD,uMsg :DWORD, wParam :DWORD, lParam :DWORD

.if uMsg == WM_CREATE

.elseif uMsg == WM_DESTROY

invoke PostQuitMessage, 0
xor eax, eax
ret

.endif

invoke DefWindowProc, hWin, uMsg, wParam, lParam

ret

WndProc endp

end start
Posted on 2002-07-15 07:19:36 by bazik
there is not RET at the end of your WndProc


sluggy,fjrp2 did use ret in the WndProc. However it is hidden in his marco :p



salir MACRO arg
mov eax, arg
ret
ENDM
Posted on 2002-07-15 09:12:11 by roticv
I haven?t been able to come back to the thread till now.
Thanks for the real-working minimum code, bAZiK.
And also


I know that you are a newbie, but that is pretty sloppy coding. You just need to take more
care, and errors like this won't happen

I know it?s sloppy (I wisj you coul see my bedroom...) they say that the code is usually similar to the coder... I?ll have to change a lot then... and "re-distribute" my neurons, or Learn from you wizards :)
I take it easy (and wait till next one ;) )
Posted on 2002-07-15 12:12:44 by slop
And also, thank you for taggint it, bAZik, how did you do it? I tryed, but It?d appear that way.
Posted on 2002-07-15 12:14:35 by slop

And also, thank you for taggint it, bAZik, how did you do it? I tryed, but It?d appear that way.


It's explained at the bottom of this page:
http://www.asmcommunity.net/board/misc.php?s=&action=bbcode

You can try it out in our TEST forum. :)


regards,
bAZiK
Posted on 2002-07-15 13:02:06 by bazik
Now with VB tags Posted on 2002-07-17 11:02:38 by slop