News:

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

RegisterClassEx i cant register :*(

Started by ScorpForeva, January 10, 2005, 10:43:07 PM

Previous topic - Next topic

ScorpForeva

all time have error ERROR_FILE_NOT_FOUND (00000002)
i used m32v8.2
Radasm 2.0.0.4
OLLYDBG
may i wrong fill wndclassex structure? what do i do wrong? sorry for my english.
.386
;.MMX

.MODEL FLAT, STDCALL

OPTION CASEMAP:none 
include windows.inc
include gdi32.inc
include user32.inc
include kernel32.inc
;
INCLUDELIB  kernel32.lib
INCLUDELIB user32.lib
INCLUDELIB  gdi32.lib

WndProc           PROTO hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
DATA?
wc WNDCLASSEX<>;
hwnd HWND  ?
msg MSG  <> ;
hInstance   HINSTANCE ?
CommandLine LPSTR ?
.DATA
szClassName   db "xxxx", 0
szAppName     db "iiiii", 0
.CONST
;WIN_h equ 640
;WIN_w equ 480
.CODE

start:
         invoke GetModuleHandle, NULL
         mov hInstance, eax
         
         invoke GetCommandLine
         mov CommandLine, eax
                                                mov wc.cbSize, SIZEOF WNDCLASSEX
         mov wc.style, CS_HREDRAW or CS_VREDRAW
         mov wc.lpfnWndProc, offset WndProc
         mov wc.cbClsExtra, NULL
         mov wc.cbWndExtra, NULL
         push hInstance
         pop wc.hInstance
         mov wc.hbrBackground,COLOR_WINDOW+1
                                                mov wc.lpszMenuName, NULL
         mov wc.lpszClassName, offset szClassName
         invoke LoadIconW, NULL, IDI_APPLICATION
                      mov wc.hIcon, eax
         xor eax, eax
         mov wc.hIconSm, eax
         invoke LoadCursor, NULL,IDC_ARROW
         mov wc.hCursor, eax
         invoke RegisterClassEx,addr wc
         invoke CreateWindowEx,WS_EX_TOPMOST, addr szClassName, addr szAppName, WS_OVERLAPPEDWINDOW,
                     CW_USEDEFAULT, CW_USEDEFAULT,CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL
         mov hwnd, eax
         invoke ShowWindow, hwnd, SW_SHOWNORMAL
         invoke UpdateWindow, hwnd
         invoke SetFocus, hwnd
         
msg_loop:
            invoke    PeekMessage, ADDR msg, 0, 0, 0, PM_NOREMOVE   
            test eax, eax
            jne message
            ;invoke Draw_Scene
         jmp msg_loop
message:             
         invoke GetMessage, ADDR msg,NULL,0,0
         test eax,eax
         je end_loop
         invoke TranslateMessage,ADDR msg
         invoke DispatchMessage,ADDR msg
         jmp msg_loop
end_loop :   
         mov eax,msg.wParam
         invoke ExitProcess,eax

      
   WndProc proc hWnd:HWND , uMsg:UINT, wParam:WPARAM, lParam:LPARAM
   cmp     uMsg, WM_CREATE
   je    wmCreate
   cmp     uMsg, WM_DESTROY
   je    wmDestroy
   invoke  DefWindowProc, hWnd, uMsg, wParam, lParam
   ret

WndProc endp


wmCreate:
          xor     eax, eax
            ret
wmDestroy :
           invoke  PostQuitMessage, NULL     
            xor     eax,eax                           
            ret
      
         
         
      
         



end start


jimh

It looks as if the includes (and includelibs) in your source are not complete try the following


include \masm32\include\windows.inc


You may need to change the path I've used here... this is just the one I use.  Also, change the other includes/includelibs in your source.  And as a side note, at a glance your RegisterClassEx looks fine.

ScorpForeva

Thanks you,ser. but project compiled & linked without errors.
its error i getting when i used debuger (olly)
or funcion getlasterror .
window don,t create
but if i maked Iczelion's simple window all well he used winmain i dont need is that funcshion
my os is xp sp1
hello for all coders from Rassia

jimh

Okay... after a bit of debugging the problem is in your WndProc procedure, not the call to RegisterClassEx or CreateWindowEx.  Change your WndProc to:


WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

    .if uMsg==WM_DESTROY
        invoke PostQuitMessage, NULL
        xor eax, eax
        ret
    .endif

    invoke DefWindowProc, hWnd, uMsg, wParam, lParam
    ret

WndProc endp


I also had to place a "." in front of the unintialized .DATA? directive, but other than that the applet compiles/runs fine.  You have to be careful what WM_* messages you handle and what you return from each one.  Depending upon the circumstances, you might have to return 0 if you handle a particular message or you might be required to call one of the default window procedures (ie. DefWindowProc/DefFrameProc, depending...).

ScorpForeva


MichaelW

A short explanation of why it was not working:

The code for the WM_CREATE and WM_DESTROY messages would have been executed within the context of WndProc, but with the labels located outside of the procedure definition, MASM was not generating the correct return code. As a result, ESP was not being restored, and both EBP and the parameters were being left on the stack.

00401153 55                     push    ebp
00401154 8BEC                   mov     ebp,esp
00401156 837D0C01               cmp     dword ptr [ebp+0Ch],1
0040115A 741B                   jz      loc_00401177
0040115C 837D0C02               cmp     dword ptr [ebp+0Ch],2
00401160 7418                   jz      loc_0040117A
00401162 FF7514                 push    dword ptr [ebp+14h]
00401165 FF7510                 push    dword ptr [ebp+10h]
00401168 FF750C                 push    dword ptr [ebp+0Ch]
0040116B FF7508                 push    dword ptr [ebp+8]
0040116E E82F000000             call    fn_004011A2
00401173 C9                     leave
00401174 C21000                 ret     10h
00401177                    loc_00401177:
00401177 33C0                   xor     eax,eax
00401179 C3                     ret
0040117A                    loc_0040117A:
0040117A 6A00                   push    0
0040117C E845000000             call    fn_004011C6
00401181 33C0                   xor     eax,eax
00401183 C3                     ret

eschew obfuscation

ScorpForeva

used code www.wasm.ru its working but not all...msdn speaked we must return create but it dont nes. we must to do wm destroy or
wm quit.