Author Topic: console program - on exit?  (Read 349 times)

Offline Darmakwolf

  • Dr. Type
  • ****
  • Posts: 343
  • Aoooooooo - the werewolves of London!
    • View Profile
console program - on exit?
« 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?

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10726
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com

Offline Darmakwolf

  • Dr. Type
  • ****
  • Posts: 343
  • Aoooooooo - the werewolves of London!
    • View Profile
Re: console program - on exit?
« Reply #2 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

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10726
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: console program - on exit?
« Reply #3 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