Shaggi Posted December 8, 2011 Share Posted December 8, 2011 (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 Edited December 8, 2011 by Shaggi Ever wanted to call functions in another process? ProcessCall UDFConsole stuff: Console UDFC Preprocessor for AutoIt OMG Link to comment Share on other sites More sharing options...
rover Posted December 9, 2011 Share Posted December 9, 2011 Any idea why the following code doesn't exit when exit is called? The callback is run in a new thread Console app 'OnAutoItExit' callback function I see fascists... Link to comment Share on other sites More sharing options...
Shaggi Posted December 9, 2011 Author Share Posted December 9, 2011 The callback is run in a new thread Console app 'OnAutoItExit' callback function Why should that affect the outcome? Can't autoit exit in callbacks? Ever wanted to call functions in another process? ProcessCall UDFConsole stuff: Console UDFC Preprocessor for AutoIt OMG Link to comment Share on other sites More sharing options...
Shaggi Posted December 10, 2011 Author Share Posted December 10, 2011 iso dev answer Ever wanted to call functions in another process? ProcessCall UDFConsole stuff: Console UDFC Preprocessor for AutoIt OMG Link to comment Share on other sites More sharing options...
trancexx Posted December 11, 2011 Share Posted December 11, 2011 (edited) You should call ExitProcess, msdn suggests. Why do you think Exit immediately calls ExitProcess, or even (imagine that)? Edited December 11, 2011 by trancexx ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Shaggi Posted December 11, 2011 Author Share Posted December 11, 2011 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 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now