It always happens in my Win32 Programs....right after a Show a Window, and I want to jump to something, as soon as I jump , the window dissappears and the program closes....try it and you'll see....like for instance

anything:
; Code
return

if you jmp anything after you show the window the window closes, automatically....why is that?
Posted on 2002-11-19 15:09:13 by CyberGuy
Could you post a minimal example that demonstrates
the behaviour?

I cant seem to duplicate it...
Posted on 2002-11-20 11:58:02 by Graebel
Ok here it is, all the code



format PE GUI 4.0
entry start

include 'include\kernel.inc'
include 'include\user.inc'

include 'include\macro\stdcall.inc'
include 'include\macro\import.inc'

section '.data' data readable writeable

mainhwnd dd 0 ; handle of window
hinstance dd 0 ; handle of module

msg MSG
wc WNDCLASS

_title db 'My Window',0
_class db 'FASMWIN32',0

section '.code' code readable executable

start:

invoke GetModuleHandle,0
mov [hinstance],eax
invoke LoadIcon,0,IDI_APPLICATION
mov [wc.hIcon],eax
invoke LoadCursor,0,IDC_ARROW
mov [wc.hCursor],eax
mov [wc.style],0
mov [wc.lpfnWndProc],WindowProc
mov [wc.cbClsExtra],0
mov [wc.cbWndExtra],0
mov eax,[hinstance]
mov [wc.hInstance],eax
mov [wc.hbrBackground],COLOR_BTNFACE+1
mov [wc.lpszMenuName],0
mov [wc.lpszClassName],_class
invoke RegisterClass,wc

invoke CreateWindowEx,0,_class,_title,WS_VISIBLE+WS_MINIMIZEBOX+WS_MAXIMIZEBOX+WS_SYSMENU+WS_THICKFRAM
mov [mainhwnd],eax
jmp anything

msg_loop:
invoke GetMessage,msg,NULL,0,0
or eax,eax
jz end_loop
invoke TranslateMessage,msg
invoke DispatchMessage,msg
jmp msg_loop

end_loop:
invoke ExitProcess,[msg.wParam]
anything:
;doesn't matter what it is
return

proc WindowProc, hwnd,wmsg,wparam,lparam
enter
push ebx esi edi
cmp [wmsg],WM_DESTROY
je wmdestroy
defwndproc:
invoke DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
jmp finish
wmdestroy:
invoke PostQuitMessage,0
xor eax,eax
finish:
pop edi esi ebx
return

section '.idata' import data readable writeable

library kernel,'KERNEL32.DLL',\
user,'USER32.DLL'

kernel:
import GetModuleHandle,'GetModuleHandleA',\
ExitProcess,'ExitProcess'

user:
import RegisterClass,'RegisterClassA',\
CreateWindowEx,'CreateWindowExA',\
DefWindowProc,'DefWindowProcA',\
GetMessage,'GetMessageA',\
TranslateMessage,'TranslateMessage',\
DispatchMessage,'DispatchMessageA',\
LoadCursor,'LoadCursorA',\
LoadIcon,'LoadIconA',\
UpdateWindow,'UpdateWindow',\
SetParent,'SetParent',\
PostQuitMessage,'PostQuitMessage'

Posted on 2002-11-20 15:56:00 by CyberGuy
This is because you are doing "return" after that jump, and this causes the program to exit. You should rather do "call anything" than "jmp anything", and use plain "ret" instead of "return", which is a macroinstruction that should be used only after the "proc" and "enter" macroinstructions.
Posted on 2002-11-20 16:37:47 by Tomasz Grysztar
Thanks Privalov!
Posted on 2002-11-21 16:34:39 by CyberGuy
I have another problem, call works but what if I want to compare something and make a jump like
cmp ,somevalue
je anything

it wouldn't work
Posted on 2002-11-22 15:36:55 by CyberGuy
If you want to call you procedure conditionally you can do it so:



cmp [something], value
jne .skip_call
call some_proc
.skip_call:
Posted on 2002-11-22 17:40:33 by wanderer
how would that work with jl, jle, jge and all the others?
Posted on 2002-11-23 14:37:00 by CyberGuy
jnl, jnle, jnge and so on :) - use your brain to generate the answer ;)
Posted on 2002-11-23 18:50:46 by wanderer
I don't have a good brain. So then to do jne you would je, its like reversed?
Posted on 2002-11-23 20:34:09 by CyberGuy
Right.
Posted on 2002-11-23 20:56:35 by wanderer