[quote=369309:@Tim Jones]Thanks @Christoph De Vocht and @Sam Rowlands - Placed Sam’s declare in the App.CancelQuit and the crash is alleviated.
I’m quoting it in this thread for posterity:
[code]/// — Make sure that all the user data and preferences are saved. #if targetMacOS then
declare function NSClassFromString lib “Cocoa” ( aClassName as CFStringRef ) as integer
declare function sharedApplication lib “Cocoa” selector “sharedApplication” ( classRef as integer ) as integer
declare sub terminate lib “Cocoa” selector “terminate:” ( appRef as integer, sender as integer )
Dim appInstance as integer = sharedApplication( NSClassFromString( "NSApplication" ) )
terminate( appInstance, appInstance )
[quote=369309:@Tim Jones]Thanks @Christoph De Vocht and @Sam Rowlands - Placed Sam’s declare in the App.CancelQuit and the crash is alleviated.
I’m quoting it in this thread for posterity:
[code]/// — Make sure that all the user data and preferences are saved. #if targetMacOS then
declare function NSClassFromString lib “Cocoa” ( aClassName as CFStringRef ) as integer
declare function sharedApplication lib “Cocoa” selector “sharedApplication” ( classRef as integer ) as integer
declare sub terminate lib “Cocoa” selector “terminate:” ( appRef as integer, sender as integer )
Dim appInstance as integer = sharedApplication( NSClassFromString( "NSApplication" ) )
terminate( appInstance, appInstance )
#endif
[/code][/quote]
There’s a Big Problem with this approach - it prevents the app from calling CancelClose on each of its windows, so if one of the window has a reason the app shouldn’t close yet (such as data not saved), the window never gets the chance to say ‘don’t close’ and the data is lost.
Don’t know much about the declare off the top of my head, but can anyone explain to me why it wouldn’t work in App.Close event? That event occurs after all of the CancelClose ones so it wouldn’t interfere as John describes.