hi,

when i call CreateWindowEx it fails (eax=0), GetLastError also returns 0....well, i can't figure out what i did wrong :/

"little" excerpt of my code:



; #################################################

.data

szClassName db "TemplateWindowClass",0
szWindowCaption db "Template Window",0



; #################################################

.data?

CommandLine dd ?
hInstance dd ?



; #################################################
;
; PROGRAM ENTRY POINT
;
; -------------------------------------------------

.code

start:
invoke GetModuleHandle,NULL
mov hInstance,eax

invoke GetCommandLine
mov CommandLine,eax

invoke WinMain,hInstance,NULL,CommandLine,SW_SHOWNORMAL
invoke ExitProcess,eax


; #################################################
;
; WINDOW PROCEDURE
;
; -------------------------------------------------

WinMain PROC hInst :DWORD,
hPrevInst :DWORD,
CmdLine :DWORD,
CmdShow :DWORD

LOCAL wc :WNDCLASSEX
LOCAL msg :MSG
LOCAL hWnd :HWND

LOCAL wTopX :DWORD
LOCAL wTopY :DWORD
LOCAL wWidth :DWORD
LOCAL wHeight :DWORD

;----------------------------------
; FILL AND REGISTER WNDCLASSEX
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov wc.cbSize, SIZEOF WNDCLASSEX
mov wc.style, CS_HREDRAW or \
CS_VREDRAW or \
CS_BYTEALIGNWINDOW
mov wc.lpfnWndProc, OFFSET WndProc
mov wc.cbClsExtra, NULL
mov wc.cbWndExtra, NULL
m2m wc.hInstance, hInst
mov wc.hbrBackground, COLOR_BTNFACE+1
mov wc.lpszMenuName, NULL
mov wc.lpszClassName, OFFSET szClassName
invoke LoadIcon,NULL,IDI_APPLICATION
mov wc.hIconSm, eax
mov wc.hIcon, eax
invoke LoadCursor,NULL,IDC_ARROW
mov wc.hCursor, eax

invoke RegisterClassEx, ADDR wc


mov wWidth,200
mov wHeight,75
mov wTopX,CW_USEDEFAULT
mov wTopY,CW_USEDEFAULT

;----------------------------
; CREATE AND SHOW WINDOW
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
invoke CreateWindowEx, NULL,
ADDR szClassName,
ADDR szWindowCaption,
WS_OVERLAPPEDWINDOW,
wTopX,wTopY,wWidth,wHeight,
NULL,
NULL,
hInst,
NULL

mov hWnd,eax


does anyone have an idea?


tarc
Posted on 2002-08-19 16:06:17 by tarc
Hi tarc: Do you have invoke ShowWindow somewhere in your code? See Iczelion's tutorial 12 for an example.
Posted on 2002-08-19 17:11:51 by Fumio
yeah i have but it doesn't work because CreateWindowEx always returns 0 for hwnd

i've attached the asm file to this reply
Posted on 2002-08-19 18:05:17 by tarc
Just a thought tarc...

Your code looks good from a quick perusal, but I noticed you didn't check eax after RegisterClassEx(). It is unusual for that one to fail, but it would explain CreateWindowEx() failing. Could be something else entirely, but I am no good at reading someone else's code :)

sulu
Posted on 2002-08-20 09:49:01 by mistersulu
The problem is not on CreateWindowEx but on how the WndProc was set up. Replace your Wndproc with this
WndProc proc hWin:DWORD,

uMsg:DWORD,
wParam:DWORD,
lParam:DWORD
.IF uMsg == WM_CREATE
invoke MessageBoxA,hWin,SADD("Window created."),SADD("SUCCESS!"),MB_OK
.ELSEIF uMsg==WM_DESTROY
invoke PostQuitMessage,NULL
.ELSE
invoke DefWindowProc,hWin,uMsg,wParam,lParam
ret
.ENDIF
xor eax,eax
ret
WndProc endp
Posted on 2002-08-20 13:00:16 by stryker
yeah it works! :alright:

thanks a lot!

tarc
Posted on 2002-08-20 17:24:14 by tarc