开发者

windows C program perform action on shutdown

I am making a program that sends "heartbeats" for a server to keep track of nodes. They are packets with the following payloads:

  • 'start' when it starts up

  • 'running' every 5 seconds

  • 'stopping' at shutdown

The first two are easy. The thread/loop can set the message on first and subsequent runs. How do I make the loop "catch" a shutdown so that it can send a last packet?

I use the minGW compiler for C in WinXP 开发者_JAVA百科platform.

Edit: I added the relevant details I missed (thanks walkingTarget and Ferruccio)

  • It is an in-progress app that contains messy stuff in implementation :-)
  • It uses libCURL, the HTTP client library to send the packets
  • It is a console app, which I (much later) intend as a service
  • It needs to save a file and send a packet at shutdown
  • It needs to capture a system shutdown


In your WindowProc() you can check for the message WM_QueryEndSession, which Windows sends to all open processes before shutting down. For more info on that message see the following link, but i understand that it is as trivial as checking for a WM_SIZE:

http://msdn.microsoft.com/en-us/library/aa376890%28VS.85%29.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜