Sign in to follow this  
Followers 0
Shaggi

Console controle handlers + bug in exit?

6 posts in this topic

#1 ·  Posted (edited)

Any idea why the following code doesn't exit when exit is called?

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Change2CUI=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <WinApi.au3>

Global $__Console__hCtrlHandler = 0
Global $__Dll_Kernel32 = DllOpen("Kernel32.dll")
If NOT __Console__SetCtrlHandler() Then MsgBox(0,_WinApi_GetLastError (),_WinApi_GetLastErrorMessage())

OnAutoItExitRegister("Cleanup")

While 1
    Sleep(1000)
WEnd

Func CleanUp()
    ConsoleWrite("Cleanup routine called!")
    Sleep(1000)
EndFunc

Func __Console__HandlerRoutine($dwSig)
    ConsoleWrite("Signal caught: " & $dwSig & @LF)
    Exit ($dwSig)
    ConsoleWrite("I should not be printed." & @LF)
    Sleep(1000)
    Return False
EndFunc

Func __Console__SetCtrlHandler()
    $__Console__hCtrlHandler = DllCallBackRegister("__Console__HandlerRoutine","bool","dword")
    Local $pCtrlHandler = DllCallBackGetPtr($__Console__hCtrlHandler)
    $aRet = DllCall($__Dll_Kernel32,"bool","SetConsoleCtrlHandler","ptr",$pCtrlHandler,"bool",1)
    If @Error OR NOT $aRet[0] OR _WinApi_GEtLastError() Then Return False
    Return True
EndFunc

Obviously,

ConsoleWrite("I should not be printed." & @LF)

Should not be printed...

E: Trigger on close ("x") of course :D

Edited by Shaggi

Ever wanted to call functions in another process? ProcessCall UDFConsole stuff: Console UDFC Preprocessor for AutoIt OMG

Share this post


Link to post
Share on other sites



#5 ·  Posted (edited)

You should call ExitProcess, msdn suggests.

Why do you think Exit immediately calls ExitProcess, or even (imagine that)?

Edited by trancexx

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

You should call ExitProcess, msdn suggests.

Why do you think Exit immediately calls ExitProcess, or even (imagine that)?

The point of registrering that callback is ofcourse to let autoit clean itself up, including anything registrered by onautoitexitregister. I figured calling exit inside that callback could do the trick, although not the cleanest way though. If i just wanted to exit the process immideatly i wouldn't need to do anything, because the console system automatically does that.

Ofcourse i dont expect exit to call exitprocess immideatly, however i do expect it not to return. that wouldn't make sense.


Ever wanted to call functions in another process? ProcessCall UDFConsole stuff: Console UDFC Preprocessor for AutoIt OMG

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0