Author Topic: error msg?  (Read 78429 times)

wjr

  • Member
  • **
  • Posts: 226
    • WJR's website
Re: error msg?
« Reply #75 on: July 12, 2012, 02:57:34 AM »
Sorry, as you most likely found out, LOCAL hWnd:DWORD and LOCAL hWnd:HANDLE do not work. The corrections for these would be LOCAL hWnd:D and LOCAL hWnd:%HANDLE.

However, since for a 32-bit application a DWORD is the default, this can be simplified to LOCAL hWnd which is better if you plan on going to 64-bit where QWORD is the default (the %HANDLE definition in the header files would also make this switch).

If you get an error, please specify the GoAsm or GoLink error message. I do not get an error using what you originally had for your CreateDC call. If you used a global variable for hWnd, I do not see how that would give an error. Given that you have had some problems with hInst, although CreateWindowExA works, does it return NULL? This is an error condition that you should generally check for, since ShowWindow and the rest are not going to work.


shankle

  • Member
  • ****
  • Posts: 868
Re: error msg?
« Reply #76 on: July 12, 2012, 10:27:56 PM »
In my test the CreateWindowEX tests as BAD.
This is the same code I use in my MASM32 version.
Regardless of the test the CreateWindowEX does not work.
No error message from GoAsm but a Window message saying the program
has stopped working. cc:codecode is a struct I defined.

WinMain:
    FRAME hInst,hPrevInst,CmdLine,CmdShow
   LOCAL msg:MSG,rc:RECT,wc:WNDCLASSEXA,cc:codecode,hWnd
; more code which is already mentioned in a prior mesage               

    INVOKE CreateWindowEx, NULL,addr szDisplayName,addr AppName,\
           WS_OVERLAPPEDWINDOW,[rc.left],[rc.top],[rc.right],\
           [rc.bottom],NULL,NULL,[hInst],NULL       
      mov   [hWnd],eax 
     
;test code begin
;szText             db   ' executed correctly',0
;szText2           db   ' is bad',0
;szCaption       db   'TRUE',0
;szCaption2     db   'FALSE',0
       pusha
          cmp D[eax], 0     ; success
           je >         
             invoke MessageBox, NULL, ADDR szText, ADDR szCaption, MB_OK
           jmp >out1
:             
             invoke MessageBox, NULL, addr szText2, addr szCaption2, MB_OK
out1:             
       popa
;test code end         
 
   INVOKE ShowWindow, [hWnd], SW_SHOWNORMAL
   INVOKE UpdateWindow, [hWnd]
   
; message loop here also mentioned in a prior message   

 

dedndave

  • Member
  • *****
  • Posts: 8829
  • Still using Abacus 2.0
    • DednDave
Re: error msg?
« Reply #77 on: July 12, 2012, 11:06:13 PM »
rc.right and rc.bottom are screen coordinates
the parameters should be width and height

another potential problem...
the window handle is generally stored in a global variable, rather than a local one
this may not be a problem, if the code is written to always use a local value

shankle

  • Member
  • ****
  • Posts: 868
Re: error msg?
« Reply #78 on: July 13, 2012, 01:06:28 AM »
Hi Dave,
The rc.bottom/rc.right are part of the RECT struct.
This worked fine in my MASM32 program.

If anything I would suspect  the trouble is caused by how I have defined  hWnd.
As far as I know I am using a Local definition of hWnd.
This also worked in the MASM32 version.

In answer to WJR the CreateWindowEX does return 0/NULL .
Question is why and what caused it?


dedndave

  • Member
  • *****
  • Posts: 8829
  • Still using Abacus 2.0
    • DednDave
Re: error msg?
« Reply #79 on: July 13, 2012, 02:22:53 AM »
what value does the WM_CREATE code in WndProc return in EAX ???
WM_CREATE should return 0 to continue creation of the window
if WM_CREATE returns -1, window creation ceases and CreateWindowEx returns 0

also - the message loop must be working properly for WM_CREATE to succeed

at any rate - you can use GetLastError for a general idea of what caused the problem
i am guessing - invalid parameter   :P
or maybe - class not found

also...
window creation causes a myriad of other messages to be sent to WndProc
like getminmaxinfo, paint, ncpaint, geticon - a bunch of em
be sure the structure of WndProc allows unhandled messages to pass to DefWindowProc   :t

wjr

  • Member
  • **
  • Posts: 226
    • WJR's website
Re: error msg?
« Reply #80 on: July 13, 2012, 03:09:03 AM »
The local hWnd looks good now. Before diving into other messages, to be on the safe side, did you fix your INVOKE WinMain as suggested back in Reply #65? If not, your value in [hInst] will be wrong causing CreateWindowEx to fail.

shankle

  • Member
  • ****
  • Posts: 868
Re: error msg?
« Reply #81 on: July 13, 2012, 04:03:51 AM »
I did make the changes requested as seen below:

pCmdline         dd       0

   invoke GetModuleHandleA, NULL
   mov    [hInstance],eax
   invoke GetCommandLine
        mov [pCmdline], eax      
   invoke WinMain, [hInstance],NULL,[pCmdline],SW_SHOWDEFAULT
   invoke ExitProcess,eax

WinMain:
    FRAME hInst,hPrevInst,CmdLine,CmdShow
   LOCAL msg:MSG,rc:RECT,wc:WNDCLASSEXA,cc:codecode,hWnd             

dedndave

  • Member
  • *****
  • Posts: 8829
  • Still using Abacus 2.0
    • DednDave
Re: error msg?
« Reply #82 on: July 13, 2012, 05:43:26 AM »
Code: [Select]
       pusha
;
;
;
       popa
PUSHA and POPA push and pop words !!!
use PUSHAD and POPAD to push and pop dword register values

Code: [Select]
    INVOKE CreateWindowEx, NULL,addr szDisplayName,addr AppName,\
           WS_OVERLAPPEDWINDOW,[rc.left],[rc.top],[rc.right],\
           [rc.bottom],NULL,NULL,[hInst],NULL     
      mov   [hWnd],eax
.if !eax
invoke GetLastError
invoke MessageBox,0,uhex$(eax),0,0
invoke ExitProcess,0
.endif

dedndave

  • Member
  • *****
  • Posts: 8829
  • Still using Abacus 2.0
    • DednDave
Re: error msg?
« Reply #83 on: July 13, 2012, 05:51:19 AM »
this code will display the error as a string, rather than a number   :biggrin:

Code: [Select]
    INVOKE  CreateWindowEx, NULL,addr szDisplayName,addr AppName,\
            WS_OVERLAPPEDWINDOW,[rc.left],[rc.top],[rc.right],\
            [rc.bottom],NULL,NULL,[hInst],NULL     
    mov     [hWnd],eax
    .if !eax
        INVOKE  GetLastError
        sub     esp,512
        xor     ecx,ecx
        mov     edx,esp
        INVOKE  FormatMessage,FORMAT_MESSAGE_FROM_SYSTEM,ecx,eax,ecx,edx,512,ecx
        mov     edx,esp
        xor     ecx,ecx
        INVOKE  MessageBox,ecx,edx,ecx,ecx
        add     esp,512
        INVOKE  ExitProcess,0
    .endif



shankle

  • Member
  • ****
  • Posts: 868
Re: error msg?
« Reply #84 on: July 13, 2012, 08:55:50 AM »
Hi Dave,
The "IF" statement in your last message  has to be changed to GoAsm format.
I have no idea how to change "!eax" to GoAsm format. I interpret it as not eax.
Otherwise I would try it.

dedndave

  • Member
  • *****
  • Posts: 8829
  • Still using Abacus 2.0
    • DednDave
Re: error msg?
« Reply #85 on: July 13, 2012, 08:57:56 AM »
.if !eax means "if not eax" or "if eax is 0"
Code: [Select]
    INVOKE  CreateWindowEx, NULL,addr szDisplayName,addr AppName,\
            WS_OVERLAPPEDWINDOW,[rc.left],[rc.top],[rc.right],\
            [rc.bottom],NULL,NULL,[hInst],NULL     
    mov     [hWnd],eax
    or      eax,eax
    jnz     around
        INVOKE  GetLastError
        sub     esp,512
        xor     ecx,ecx
        mov     edx,esp
        INVOKE  FormatMessage,FORMAT_MESSAGE_FROM_SYSTEM,ecx,eax,ecx,edx,512,ecx
        mov     edx,esp
        xor     ecx,ecx
        INVOKE  MessageBox,ecx,edx,ecx,ecx
        add     esp,512
        INVOKE  ExitProcess,0
around:

shankle

  • Member
  • ****
  • Posts: 868
Re: error msg?
« Reply #86 on: July 13, 2012, 10:52:42 PM »
Hi Dave,
Added your code with the small change to conform to GoAsm format.

    cmp D[eax],0
      jnz > around

Maybe this sequence might shed some light on the problem.
I have message boxes at Start, just before CreatWindowEX in winmain and
at the end of WM_CREATE. I have Dave's error code just after the CREATEWINDOWEX.
When I run the program these messagebox messages occur in this order:
Start, WinMain, WM_CREATE, BOMB. The program is supposed to return to
CreatWindowEX after WM_CREATE. Then Dave's error code check would execute
if an error occurred. Instead a windows message occurs stating that the program
has stopped working.
« Last Edit: July 14, 2012, 12:26:34 AM by shankle »

dedndave

  • Member
  • *****
  • Posts: 8829
  • Still using Abacus 2.0
    • DednDave
Re: error msg?
« Reply #87 on: July 14, 2012, 02:04:37 AM »
Quote
Instead a windows message occurs stating that the program has stopped working.

i hope it says more than that   :P

i would have to guess there is a problem with WndProc
but - it could be the message loop, as well

make sure WndProc is set up correctly, in general:
EBX, EBP, ESI, EDI are preserved (or not destroyed)
the routine pops 4 dword parms when it returns (RET 16)
unhandled messages invoke DefWindowProc and return it's value from EAX

you could put a temporary version of WndProc in there that handles a minimal number of messages
for example - if it just handles WM_CLOSE and WM_DESTROY
at least you can see if a window appears
in fact, all you need is DefWindowProc and a RET (close is nice, though)
Code: [Select]
    INVOKE  DefWindowProc,hWnd,uMsg,wParam,lParam
    ret

you might disassemble the code
sometimes, the problem glares at you from the disassembled code, while the source format hides it

attach the EXE to your next post - i'll have a look

Ryan

  • Guest
Re: error msg?
« Reply #88 on: July 14, 2012, 04:15:31 AM »
Correct me if I'm wrong, but you need to handle WM_DESTROY with a PostQuitMessage, no?  Without it the window will close, but the process will remain running.  DefWindowProc does not do it.

dedndave

  • Member
  • *****
  • Posts: 8829
  • Still using Abacus 2.0
    • DednDave
Re: error msg?
« Reply #89 on: July 14, 2012, 05:00:16 AM »
yes - that's what i say
but - you can assemble and run without it - then use the task manager to close it

the idea here is a one-time temporary test to see if things are put together right