Hey,
Would be nice to see a feature implemented where the programmer can 'register' a procedure that automatically gets called when the application ends.
I know it could just be added at the bottom of the source code, but in instances where 'End' is called, or the console is closed etc, it wouldn't apply.
For example, I use a piece of hardware that acts as a kind of relay board, controlled by a DLL, connected by USB.. If I don't explicitly uninitialize the library, it causes a crash, and with it being a console program, a program closure can happen at any time, so having a function that will be called without fail ensures I can correctly release the library, thus preventing unwanted effects.
Obviously the functionality of this feature can be applied to all kinds of situations.
Call procedure on End
Call procedure on End
Thanks!
Re: Call procedure on End
I don't know if there's a way to intercept closing a console, but here's how I would do it.
Just register Quit as a Keyword in the preferences and you're good to go.
Code: Select all
Macro Quit
Debug "END called"
End
EndMacro
hWnd = OpenWindow(#PB_Any, 0, 0, 800, 600, "", #PB_Window_ScreenCentered|#PB_Window_MinimizeGadget)
Repeat
event = WaitWindowEvent(20)
Until event = #PB_Event_CloseWindow
Quit
Re: Call procedure on End
I use this in almost every program I write:
And then I only call Shutdown() from elsewhere in the program, never call End.
Code: Select all
Procedure Shutdown()
; Free up memory, lists, libraries, etc.
; Save settings, yada yada, other finalization
End
EndProcedure
Re: Call procedure on End
You can do it like this too:
This way you can have several Shutdown() procedures for doing different things (mostly dependant on what you have to clean up).
Code: Select all
Procedure Shutdown()
EndProcedure
;...
End Shutdown()
Re: Call procedure on End
Thanks eesau
I thought End [ExitCode] only meant a simple numeric like End 999.

I thought End [ExitCode] only meant a simple numeric like End 999.
Code: Select all
Procedure Shutdown()
i = -1
Debug i
EndProcedure
Global.i i
i = 10
Debug i
End Shutdown()
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Re: Call procedure on End
So what's the difference between
and

Except for the obivious reasons that the return of ShutDown() can somehow be obtained by another program...
Code: Select all
ShutDown()
End
Code: Select all
End ShutDown()

Except for the obivious reasons that the return of ShutDown() can somehow be obtained by another program...
Re: Call procedure on End
It's one line shorter 
