Hallo to all and goodnight.
I,m having trouble figuring this one out.
Its iczelion multithread tutorial number 15 to be exact( attachment included).
I,m not a champion debugger, but for what i could figure out ,is that MessageLoop:
invoke GetMessage,addr msg,0,0,0 ; Retrieves a message from the calling thread's message queue
or eax,eax
jz >ExitProgram
invoke TranslateMessage,addr msg
invoke DispatchMessage, addr msg
jmp <MessageLoop
ExitProgram:
int 3 ; For testing purpose only
invoke ExitProcess,[msg.wParam]
it looks like the debugger never reaches the int3 instruction and also it never reaches a breakpoint before the exitcode ( on the push ), or on the exitcode api call itself.
I,m missing something, but i can't put my finger on it.
The Thread itself exit with non zero.
Help is much appreciated.
Thank you.
Executes fine here Vista x86-32
Quote from: Dogim on November 17, 2010, 08:58:51 PM
MessageLoop:
invoke GetMessage,addr msg,0,0,0 ; Retrieves a message from the calling thread's message queue
or eax,eax
jz >ExitProgram
invoke TranslateMessage,addr msg
invoke DispatchMessage, addr msg
jmp <MessageLoop
ExitProgram:
int 3 ; For testing purpose only
invoke ExitProcess,[msg.wParam]
it looks like the debugger never reaches the int3 instruction and also it never reaches a breakpoint before the exitcode ( on the push ), or on the exitcode api call itself.
I,m missing something, but i can't put my finger on it.
The Thread itself exit with non zero.
Help is much appreciated.
Thank you.
What if change the piece of message loop to:
invoke GetMessage,addr msg,0,0,0 ; Retrieves a message from the calling thread's message queue
or eax,eax
jle >ExitProgram <--- CHANGED THIS
This is not help?
Quote from: donkey on November 17, 2010, 09:46:43 PM
Executes fine here Vista x86-32
Hi Donkey, it does execute on my Win 7 64 Bits OS, but the primary Thread does not exit, so in Rad when try to recompile it, i get can't delete error, a Ctrl Alt Del shows it still running in the background.
Hi Dogim,
I spoke too soon, the problem with the exit is only present when you use the menu to exit, I was using the close button. You should post a WM_CLOSE message instead of DestroyWindow, DestoryWindow will flush the message queue so you will not receive the NULL return from GetMessage (as far as I have been able to determine).
.kill_and_exit
invoke PostMessage,WM_CLOSE,0,0
jmp >.defwindowproc
So, my suggestion about using of "jle >ExitProgram" is fully ignored :P
PROBLEM SOLVED fixed, Thanks Donkey and Antariy for the help.
Quote from: Antariy on November 17, 2010, 10:16:51 PM
So, my suggestion about using of "jle >ExitProgram" is fully ignored :P
No i did not ignore your fix, but Donkey was so fast with his answer , i didn't get the chance to reply to your answer :U :bg
I used both fixes :lol
Quote from: Dogim on November 17, 2010, 10:21:38 PM
Quote from: Antariy on November 17, 2010, 10:16:51 PM
So, my suggestion about using of "jle >ExitProgram" is fully ignored :P
No i did not ignore your fix, but Donkey was so fast with his answer , i didn't get the chance to reply to your answer :U :bg
I used both fixes :lol
Just using of jle is as rule - if you destroy window, then GetMessage return value less than 0. If WM_QUIT is received, then GetMessage return 0 - JLE check for zero or negative value :U
Quote from: Antariy on November 17, 2010, 10:26:59 PM
Quote from: Dogim on November 17, 2010, 10:21:38 PM
Quote from: Antariy on November 17, 2010, 10:16:51 PM
So, my suggestion about using of "jle >ExitProgram" is fully ignored :P
No i did not ignore your fix, but Donkey was so fast with his answer , i didn't get the chance to reply to your answer :U :bg
I used both fixes :lol
Just using of jle is as rule - if you destroy window, then GetMessage return value less than 0. If WM_QUIT is received, then GetMessage return 0 - JLE check for zero or negative value :U
Hi Antariy , the jle>ExitProgram in combination with Destroywindow function, still keeps it running in the background, when i exit using the menu,exit true the menu only works when i send a WM_CLOSE message as Donkey stated in his answer.
Quote from: Dogim on November 17, 2010, 10:41:53 PM
Hi Antariy , the jle>ExitProgram in combination with Destroywindow function, still keeps it running in the background, when i exit using the menu,exit true the menu only works when i send a WM_CLOSE message as Donkey stated in his answer.
Did not you call
PostQuitMessage or
SendMessage,hwnd,WM_QUIT,0,0 before DestroyWindow? That must be at this manner.
Quote
Did not you call PostQuitMessage or SendMessage,hwnd,WM_QUIT,0,0 before DestroyWindow? That must be at this manner.
.wmfinish
cmp D[uMsg],WM_FINISH
jne >>.defwindowproc
invoke MessageBoxEx,NULL,ADDR szMbString,ADDR szAppName,MB_OK,0
;jmp >.exit -->FIXED
jmp >.defwindowproc
.kill_and_exit
: invoke DestroyWindow,[hWnd]
: jmp >.exit
invoke PostMessage,[hWnd],WM_CLOSE,0,0 -->FIXED
jmp >.defwindowproc ---FIXED
The above code works with jle > ExitProgram, I called the destroywindow api at first, but i discovered that when i processed the WM_FINISH message i was jumping to >.exit, i should continue to DefWinProc here i think.But however, this way the programs exit true the close and also true the menu.
Quote from: Dogim on November 17, 2010, 10:59:21 PM
Quote
Did not you call PostQuitMessage or SendMessage,hwnd,WM_QUIT,0,0 before DestroyWindow? That must be at this manner.
.wmfinish
cmp D[uMsg],WM_FINISH
jne >>.defwindowproc
invoke MessageBoxEx,NULL,ADDR szMbString,ADDR szAppName,MB_OK,0
;jmp >.exit -->FIXED
jmp >.defwindowproc
.kill_and_exit
: invoke DestroyWindow,[hWnd]
: jmp >.exit
invoke PostMessage,[hWnd],WM_CLOSE,0,0 -->FIXED
jmp >.defwindowproc ---FIXED
The above code works with jle > ExitProgram, I called the destroywindow api at first, but i discovered that when i processed the WM_FINISH message i was jumping to >.exit, i should continue to DefWinProc here i think.But however, this way the programs exit true the close and also true the menu.
Usual sequence is PostQuitMessage (or sending of WM_QUIT), and after that - DestroyWindow.
You can make reaction for WM_FINISH like this:
invoke SendMessage,[hWnd],WM_CLOSE,0,0
ret
Or something like - sorry, I'm not very familar with GoAsm yet.
Quote from: Antariy on November 17, 2010, 11:12:39 PM
Usual sequence is PostQuitMessage (or sending of WM_QUIT), and after that - DestroyWindow.
You can make reaction for WM_FINISH like this:
invoke SendMessage,[hWnd],WM_CLOSE,0,0
ret
Or something like - sorry, I'm not very familar with GoAsm yet.
This Will shutdown the whole program as soon as the secondary Thread stops executing, so if you want to restart the secondary thread again, your gonna have to start the whole program again.
Quote from: Dogim on November 17, 2010, 11:27:02 PM
Quote from: Antariy on November 17, 2010, 11:12:39 PM
Usual sequence is PostQuitMessage (or sending of WM_QUIT), and after that - DestroyWindow.
You can make reaction for WM_FINISH like this:
invoke SendMessage,[hWnd],WM_CLOSE,0,0
ret
Or something like - sorry, I'm not very familar with GoAsm yet.
This Will shutdown the whole program as soon as the secondary Thread stops executing, so if you want to restart the secondary thread again, your gonna have to start the whole program again.
Well, I'm not dig into the program itself. I just suggest a sequence of things to close window, you can adapt anything for your needs :U
Quote from: Antariy on November 17, 2010, 11:34:46 PM
Quote from: Dogim on November 17, 2010, 11:27:02 PM
Quote from: Antariy on November 17, 2010, 11:12:39 PM
Usual sequence is PostQuitMessage (or sending of WM_QUIT), and after that - DestroyWindow.
You can make reaction for WM_FINISH like this:
invoke SendMessage,[hWnd],WM_CLOSE,0,0
ret
Or something like - sorry, I'm not very familar with GoAsm yet.
This Will shutdown the whole program as soon as the secondary Thread stops executing, so if you want to restart the secondary thread again, your gonna have to start the whole program again.
Well, I'm not dig into the program itself. I just suggest a sequence of things to close window, you can adapt anything for your needs :U
Thanks for all the tips, it does work however, so ill use all in my further programming journey :U
Hi Dogim,
Some unsolicited advice:
NEVER use SendMessage or PostMessage to send a WM_QUIT message, the only reliable way to use that message is PostQuitMessage. When sending the WM_CLOSE message to your own application be sure to use PostMessage, SendMessage will wait for it to return and though it does not currently present a problem it may on future versions of Windows if the window destructor sequence is changed. I usually use WM_CLOSE as it allows my program to process all unfinished business and free resources within a single message handler, PostQuitMessage can be executed from the WM_CLOSE handler so that the Close button and the Exit menu item will execute the same wrap up code. Also I found out early that using PostQuitMessage all over the program can complicate debugging on larger programs, a single call in the WM_CLOSE handler is much easier to deal with.
Edgar
Quote from: donkey on November 17, 2010, 11:48:54 PM
Hi Dogim,
Some unsolicited advice:
NEVER use SendMessage or PostMessage to send a WM_QUIT message, the only reliable way to use that message is PostQuitMessage. When sending the WM_CLOSE message to your own application be sure to use PostMessage, SendMessage will wait for it to return and though it does not currently present a problem it may on future versions of Windows if the window destructor sequence is changed. I usually use WM_CLOSE as it allows my program to process all unfinished business and free resources within a single message handler, PostQuitMessage can be executed from the WM_CLOSE handler so that the Close button and the Exit menu item will execute the same wrap up code. Also I found out early that using PostQuitMessage all over the program can complicate debugging on larger programs, a single call in the WM_CLOSE handler is much easier to deal with.
Edgar
Yes, right, using of SendMessage is not proper. I'm too tired. But with using of PostMessage,WM_QUIT... I never had a problems, really.
Quote from: Antariy on November 18, 2010, 12:00:16 AM
Yes, right, using of SendMessage is not proper. I'm too tired. But with using of PostMessage,WM_QUIT... I never had a problems, really.
Perhaps you got lucky, I am looking for an old Win98SE program I had that BSODed when it was sent without PostQuitMessage, something in the window procedure that the program was doing caused a lock-up.
Quote from: MSDNRemarks
The WM_QUIT message is not associated with a window and therefore will never be received through a window's window procedure. It is retrieved only by the GetMessage or PeekMessage functions.
Do not post the WM_QUIT message using the PostMessage function; use PostQuitMessage.
Edgar
Quote from: donkey on November 18, 2010, 12:07:26 AM
Quote from: Antariy on November 18, 2010, 12:00:16 AM
Yes, right, using of SendMessage is not proper. I'm too tired. But with using of PostMessage,WM_QUIT... I never had a problems, really.
Perhaps you got lucky, I am looking for an old Win98SE program I had that BSODed when it was sent without PostQuitMessage, something in the window procedure that the program was doing caused a lock-up.
Quote from: MSDNRemarks
The WM_QUIT message is not associated with a window and therefore will never be received through a window's window procedure. It is retrieved only by the GetMessage or PeekMessage functions.
Do not post the WM_QUIT message using the PostMessage function; use PostQuitMessage.
Edgar
Thanks Donkey for the tip. :U