Minions Gaming
Minions Gaming

Reputation: 1

how to initialization script C++ before windows shutdown

i have no ideal for initialization code c++ before windows shutdown. For protect algorithm of my code when running. Any ideal here?

Upvotes: 0

Views: 63

Answers (2)

Joshua
Joshua

Reputation: 43327

I am not sorry to report you cannot do this reliably. You can handle WM_QUERYENDSESSION or WM_ENDSESSION Windows messages, but that really traps logoff not shutdown. Alternately you could try a Windows service and react to the stop signal. But that is exactly that, your service being stopped.

HOWEVER; none of this happens reliably. If you have some defenses best broken by the shutdown code not running, somebody who wants to break them will just power the machine off. If I thought you were writing software that needed to be fault tolerant I would now advise you on crash-only software.

To make a backing store that can survive being powered off without being corrupted, the cheapest way is to use sqlite.

Upvotes: 1

Tiefan Ju
Tiefan Ju

Reputation: 520

I think you should create an object of your own class and write something inside the destructor (or ~YourClass()).

Upvotes: 0

Related Questions