CreatWindowEx returns error 6 when i change my winproc.???

Started by bigantiman, April 04, 2005, 11:06:28 PM

Previous topic - Next topic

bigantiman

Hello 2 all :green
I'm a n00b who trying to learn assembly prgramming the hard way.by this i mean that the only programming experience that i have with other higher language is the examples that came with the  C/C++ books that i have bought.
But i still feel more atracted to assembly language and maybe i could marry it someday :lol ( sorry for the wacky english).
2 the point.
I keep getting this 6 error as soon as i change the break scheme in my window procedure.
The program alows me to do thismov eax,0  and then  do the     jmp EX_OUT
This doesn't cause any problems,( simulates break in a case situation i think
The jump to EX_OUT is where i return to the OS with eax,0 ( at least if i payed attention 2 my book).
Ok for those who has the latest clue of what i'm talking abouth i includded the code.
i use RadAsm IDE.
So the question is why doesn´t it work.
Anybody  :toothy

[code.586
.model flat,stdcall
option casemap:none


   include windows.inc
   include user32.inc
   include kernel32.inc
   include comctl32.inc
   include gdi32.inc
   include \masm32\macros\macros.asm     ; the macro file

   includelib user32.lib
   includelib gdi32.lib
   includelib kernel32.lib
   includelib comctl32.lib

_DATA SEGMENT PUBLIC USE32 'DATA'
   hWnd         DD   0
   hInstance      DD   ?
   
    CommandLine    DD  ?
   
   message         MSG <?>
   WC            WNDCLASS <?>   
   hinst         dd   0      ; application description
   titleName      db   'A BigantiMan Software (C)opyright 2005',0
   className      db   'my_program_name_class32',0
   
   
   messCap         db    "Message",0
   errCap         db   "Error message",0
   errText         db   "Sotware Error number [ %u ]",0
   myBuffer      db   50 dup(0)
_DATA ENDS


;=========================================
; CODE SEGMENT
;=========================================

_TEXT SEGMENT PUBLIC USE32 'CODE'
START:
   invoke   InitCommonControls
;GET THE APPLICATION DESCRIPTION
   invoke   GetModuleHandle,NULL
   mov     [hInstance],eax
   
   invoke   GetCommandLine
   mov     [CommandLine],eax
   
;-----------------------------------------
; REGISTER OUR CLASS WINDOW HERE
;-----------------------------------------
   
REG_CLASS:
   mov   [WC.style], WS_OVERLAPPED or WS_TABSTOP
   mov   [WC.lpfnWndProc],OFFSET WndProc
   mov   [WC.cbClsExtra],0
   mov   [WC.cbWndExtra],0
   mov   eax,[hInstance]
   mov   [WC.hInstance],eax
   
;----- WINDOW ICON
   invoke   LoadIcon,NULL,IDI_APPLICATION
   mov   [WC.hIcon],eax
   
;------ WINDOW CURSOR
   
   
   invoke   LoadCursor,NULL,IDC_CROSS
   mov   [WC.hCursor],eax
   
;------- WINDOW BACKGROUND AND CLASS AND MENU NAME
   
   invoke   GetStockObject,WHITE_BRUSH
   
   mov      [WC.hbrBackground],eax
   mov      DWORD PTR [WC.lpszMenuName],0
   mov      DWORD PTR [WC.lpszClassName], OFFSET className
   
;--------REGISTER THE CLASS
   invoke   RegisterClass,ADDR WC
   
;------- WINDOW CREATION

      
   invoke   CreateWindowEx,NULL,ADDR className,ADDR titleName,WS_OVERLAPPEDWINDOW,100,100,800,600,NULL,NULL,[hInstance],NULL
   
;CHECK ERRORS HERE
   cmp      eax,0               ; Do we have an error ??
   jz      ERROR_DETECTED         ; YES IT'S was A NULL SO BOUNCE
   mov      [hWnd],eax            ; NO ERROR SO SAVE OUR HANDLE
   
   
   
   invoke   ShowWindow,[hWnd],SW_SHOWNORMAL            ; SHOW THE WINDOWS NORMALMODE
   
   
   invoke   UpdateWindow,[hWnd]
   
;----- MESSAGE HANDLING LOOP

MSG_LOOP:
   
   invoke   GetMessage,ADDR message,NULL,NULL,NULL      ; Get the Message waiting
   cmp      eax,0                              ; Check to see if its a Exit
   je      EXIT_LOOP                           ; Yes exit the loop
   
   invoke   TranslateMessage,ADDR message            ; No... translate it
   invoke   DispatchMessage,ADDR message            ; Dispatch it
   jmp      MSG_LOOP                           ; Do it all over again
EXIT_LOOP:                  
   invoke   ExitProcess,[message.wParam]            ; Please ... do i have to.???
ERROR_DETECTED:
;---------------------------------------------------
; Come here for Error after we call CreateWindowEx function
;==================================================
   invoke GetLastError         ; Get The Last Error
   movzx  eax,ax            ; convert 16bit 2 32 bit
   invoke wsprintf,ADDR myBuffer,addr errText,eax
   ;TO DO Get he Erro in a buffer
   invoke MessageBoxEx,hWnd,ADDR myBuffer,SADD("Message"),MB_ICONEXCLAMATION or MB_ICONWARNING,NULL

   jmp      EXIT_LOOP
   


WndProc   PROC
; Win proc is a Callback Proc
; Windows Pushes these Parameters before calling our proc
; [EBP+014H] or [EBP+20] -----> LPARAM 
; [EBP+010H] or [EBP+16] -----> WPARAM   
; [EBP+00CH] or [EBP+12] -----> MESSAGE
; [EBP+0008] or [EBP+08] -----> hWnd
; [EBP+0004] or [EBP+04] -----> Return Adress
; [EBP+0000] or [EBP+00] -----> Base Muchu Base baby
   
   push   ebp
   mov      ebp,esp                           ; Setup the stack
   push   ebx                              ; save (OBLGIGATORY Microsoft registers )
   push   esi
   push   edi
;--- Message checking      
   cmp      dword ptr [ebp+012],WM_DESTROY
   jne      CHK_MESS_001                     ; No Check For The Next Message
   invoke   PostQuitMessage,0
   jmp      EX_OUT
   
CHK_MESS_001:
   cmp      dword ptr [ebp+012],WM_CREATE
   jne      DEF_WIN_PROC
;---WM_CREATE MESSAGE HANDLER-----------------
   ;mov      eax,0                        ; OLD WAY WORKS GOOD
   jmp      EX_OUT


DEF_WIN_PROC:
;=================== PARAMETERS ARE ON THE STACK =========================

   
   invoke   DefWindowProc,dword ptr [ebp+008],\   ;hWnd
                    dword ptr [ebp+012],\ ;Message
                    dword ptr [ebp+016],\ ;wParam
                    dword ptr [ebp+020]   ;lParam
EX_OUT:
;--------------PROBLEM PROBLEM--------
   ;xor      eax,eax                           ; THIS DOESN'T WORK         
   pop      edi
   pop      esi                                 ; restore registers
   pop      ebx
   pop      ebp
   ;xor      eax,eax                              ; THIS DOESNT WORK
   mov      eax,0
   ret   16                                       ; Clean the stack pops the para's off the stack
   
WndProc ENDP
_TEXT ENDS
END START
   


hitchhikr

It's because the events you're not intercepting are handled by DefWindowProc which doesn't necessary return 0 as in WM_NCCREATE:

"If an application processes this message, it should return TRUE to continue creation of the window. If the application returns FALSE, the CreateWindow or CreateWindowEx function will return a NULL handle."

Download the sdk from microsoft's website.

bigantiman

Quote from: hitchhikr on April 05, 2005, 02:31:56 AM
It's because the events you're not intercepting are handled by DefWindowProc which doesn't necessary return 0 as in WM_NCCREATE:

Wel thanks hitchhikr.
I must of been sleeping on this chapter in the Great Big  Petzold book.
But thanks for the reply, gonna do some reading.
By the way, your site rocks, i like the IDE,lots of brainfood ,cool stuffs.
Maybe in abouth 100 years i could be making (as you call it ) Useless software like that, wow love those intro's
:wink