0

This is a bit of an "edge" case probably but I would be really grateful for ideas how to achieve this.

I've built a "fruit machine" cabinet that has a PC installed that runs some fruit machine emulation software. The PC isn't easily accessible so I've installed a 'physical' power on/off button, in easy reach, that is wired back to the power switch on the PC.

I've set up Windows 7 advanced power settings so that this button powers the PC on/off.

So far, so good... Unfortunately, when powering down the system hangs with a "access violation at address 007352BB in module mfme.exe. read of address 0000006c" message (mfme.exe being the software that is emulating the fruit machine).

A possible solution I thought of would be to write a small application that runs in the background and "intercepts" the power down trigger to kill the mfme.exe process first before the PC continues to shut down.

Is this possible?

John T
  • 1,078
  • 3
  • 14
  • 29
  • 1
    Have you tried asking about your original problem on [Super User](https://superuser.com/)? –  Jul 19 '17 at 07:59
  • 2
    Why not just implement functionality in mfme.exe to intercept the Windows messages related to shutdown and ensure your app shuts down correctly? Or is the emulation software third-party? btw if mfme.exe doesn't shutdown when notified by Windows, Windows will kill it. Are you sure you'll be able to kill it more successfully than Windows? – Disillusioned Jul 19 '17 at 07:59
  • 2
    Possible duplicate of [How can I Execute a Function when Windows Shut down](https://stackoverflow.com/questions/4095517/how-can-i-execute-a-function-when-windows-shut-down) – o_weisman Jul 19 '17 at 08:00
  • @FelixPalmen I'd not seen Super User before. I'll bear that in mind as my next port of call if it doesn't get resolved here. Thanks. – John T Jul 19 '17 at 08:03
  • @CraigYoung mfme.exe is not my software so I can't tinker with it. It's just a process that is blocking windows closing. Thanks :) – John T Jul 19 '17 at 08:04
  • 1
    @JohnT it's just an idea because I don't think writing a program to solve this is the best idea. As CraigYoung said, Windows normally shouldn't have a problem killing a process that doesn't react in time. –  Jul 19 '17 at 08:05
  • @FelixPalmen will pop the question then and see what they say. Thanks again :) – John T Jul 19 '17 at 08:07
  • 1
    @JohnT Cool, just clarifying. Check the poss-dup link to see if that helps. Also check out this info from MS https://msdn.microsoft.com/en-us/library/ms700677(v=vs.85).aspx – Disillusioned Jul 19 '17 at 08:07
  • @CraigYoung Thanks Craig. Will read and digest. I've also asked the Super User group if there's a way of making "force shutdown" the default behaviour without Windows asking. I think this would also be a solution. Cheers :) – John T Jul 19 '17 at 08:13

2 Answers2

2

When the system is about to shut down, the applications with a window and message queue receive shutdown notifications through the WM_QUERYENDSESSION and WM_ENDSESSION messages.

Handle the WM_ENDSESSION message to do the cleanup but don't worry about releasing memory or in-memory system resources; do only what is really needed (flush and close files f.e.). The system is going to turn off and there is no point in releasing memory or other system resources that are not persistent.

axiac
  • 68,258
  • 9
  • 99
  • 134
  • thanks for the answer. I've actually ended up with a different solution (which I've posted) but, as your answer is strictly correct within the boundaries of the question I asked then I've accepted your answer. Thanks again :) – John T Jul 19 '17 at 09:01
0

I have a solution to my question. I'm going to 'accept' axiac as their answer strictly answers the question I've asked within the framework of C++.

However, I've found an alternative solution that will work which I'm going to post here to give someone in the future another method of achieving the same thing.

The following instructions will, essentially, set the PC to 'force shutdown' everything without any kind of prompt etc upon shutdown.

1.Press "Window +R" keys to start "Run" dialogue box and type "gpedit.msc" in the dialogue box.

2.Click "OK", "Local Group Policy Editor" window will pop up.

3.Navigate to "Computer Configuration" --> "Administrative Templates" --> "System" --> "Shutdown Options". Double-click "Turn off automatic termination of applications that block or cancel shutdown" on the right panel. In the new dialogue box popped up, set configuration option as "Enabled".

4.Next time when you shut down your machine, the machine will be shut down directly without prompt.

Thanks to everyone for all their help. :)

John T
  • 1,078
  • 3
  • 14
  • 29