console program - on exit?

Previous topic - Next topic

Darmakwolf

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?

Kitty Hello


Darmakwolf

Quote from: Kitty Hello on 2019-Dec-07
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

Kitty Hello

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