GLBasic forum

Main forum => GLBasic - en => Topic started by: Darmakwolf on 2019-Dec-02

Title: console program - on exit?
Post by: Darmakwolf on 2019-Dec-02
GLB_ON_QUIT does not seem to fire with a console program. How can I make something happen when the window is closed or ctrl+c is pressed?
Title: Re: console program - on exit?
Post by: Kitty Hello on 2019-Dec-07
Implement atexit:
http://www.cplusplus.com/reference/cstdlib/atexit/
Title: Re: console program - on exit?
Post by: Darmakwolf on 2019-Dec-08
Implement atexit:
http://www.cplusplus.com/reference/cstdlib/atexit/


HelloKitty - I am not very good at INLINE and implementing C++ stuff. Could you or someone please show me how to make a SUB that is called when exiting?

Thank you so much <3
Title: Re: console program - on exit?
Post by: Kitty Hello on 2019-Dec-10
Here's a minimal example that works for me. It might NOT work for x64 builds, yet. The problem is the atexit(int) argument.
Code: (glbasic) [Select]
IMPORT "C" void atexit(int)

atexit(ADDRESSOF(OnConsoleExit))


FUNCTION OnConsoleExit%:
STDOUT "Wohoo\n"
KEYWAIT
ENDSUB