I’m afraid with C++ matters you may not get a lot of help here.
JavaScript could be used to open a file and in Photoshop the Save Event could be linked to quitting Photoshop (File > Scripts > Script Event Manager) but that would seem a bad idea to me.