Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How do safe shutdown programmatically?

21 views
Skip to first unread message

Andi B.

unread,
Oct 29, 2017, 7:01:18 AM10/29/17
to
Hi,
I want to shut down the system from my program. I can do it the ACPI toolkit way -

AcpiTkPrepareToSleep(ACPI_STATE_S5);
rc = DosShutdown(0L);
DosSleep(3000); /* Wait allows shutdown to complete */
rc = AcpiTkGoToSleep(&Hdl, ACPI_STATE_S5);

But PowerOff.c still states 'Created 2005 eCo Software'. I'm pretty sure the code is
changed by David afterwards but usually when he does he adds name and date. So I'm not
sure if this is really the latest and best way to shut down / power off. Moreover this
code does shut down my T60 so fast that I think running application may not have a chance
to properly close down and save files before shutting down.

I want a clean shut down like xwp extended shutdown feature. With all application closes
cleanly. So I guess I could call some xwp code to to it for me. But how to do? Is there a
xwp api to start extended shut down?

If I would send a WM_QUIT myself to all running programs I think this would be reinventing
the wheel again. On the other hand if I would let some other program send WM_QUIT to all
programs, my own program will get it too and may close before I can AcpiTkGoToSleep. I
would need to assure my program is the last one which is closed in this scenario.

I can call some system(shutdown.exe). But which one is the best? I tried the default on my
T60 installation (upgraded eCS2.x) and it end up with the message box - shutdown completed
you can now power off the system. But I don't want to power off by myself. That's the task
of ACPI (APM on older systems).

AcpiStat poweroff does the same as the Acpi toolkit poweroff. At least when looking at the
sources from -
* Rewritten by: David Azarewicz
* Copyright (c) 2011-2012 Mensys BV

No clue where I got it. Are there newer versions available?

Any thoughts welcome.

Andreas

Andi B.

unread,
Oct 29, 2017, 7:01:51 AM10/29/17
to

Andreas Schnellbacher

unread,
Nov 1, 2017, 4:21:44 PM11/1/17
to
On 29.10.17 12:58, Andi B. wrote:

> I want a clean shut down like xwp extended shutdown feature. With all application
> closes cleanly.

Then you should probably better use XWP funcs.

> So I guess I could call some xwp code to to it for me. But how to do? Is there a
> xwp api to start extended shut down?

The file "xworkplace\branch-1-0\src\startshut\shutdown.c" looks interesting.

--
Andreas Schnellbacher

Andi B.

unread,
Nov 3, 2017, 12:58:53 PM11/3/17
to
Andreas Schnellbacher schrieb:
I think there must be a simpler method than integrating xwp code in my
own program. Something like 'send xwp (xcenter) button extended
shutdown'. Maybe the sendmsg package can do something like this?

Andreas

Andi B.

unread,
Nov 5, 2017, 5:31:42 AM11/5/17
to
Andi B. schrieb:
Just found \XWorkplace\bin\xshutdwn.cmd. It's as simple as system("xshutdwn.cmd");

Solved. :-)

Andi B.

unread,
Nov 5, 2017, 7:40:26 AM11/5/17
to
Andi B. schrieb:
Even better -
object = WinQueryObject("<WP_DESKTOP>");
fSuccess = WinSetObjectData(object,"XSHUTDOWNNOW=POWEROFF,NOCONFIRM;");

Andreas

Lars Erdmann

unread,
Nov 5, 2017, 9:36:39 AM11/5/17
to
Just for the record:

if you want to have PM applications notified on shutdown you need to use
"WinShutdownSystem" API function. That will also eventually call
DosShutdown.

Lars


Andi B. schrieb:
> Andi B. schrieb:
>

Pete

unread,
Feb 5, 2019, 9:14:05 PM2/5/19
to
Hi
I was looking into adding reboot capability to an app, USBcfg, and
noticed this thread.

Changing the above slightly for use with the WDSibyl pascal "dialect"
and using REBOOT instead of POWEROFF works great.

Dobject = WinQueryObject('<WP_DESKTOP>');
fSuccess = WinSetObjectData(object,'XSHUTDOWNNOW=REBOOT,NOCONFIRM;');


Thanks.


Pete

0 new messages