Article View: borland.public.cppbuilder.nativeapi
Article #10351Re: Custom Shutdown
From: Remy Lebeau (TeamB)
Date: Tue, 20 Apr 2004 02:50
Date: Tue, 20 Apr 2004 02:50
82 lines
3549 bytes
3549 bytes
"Malcolm Smith" <m.smith@comvision.net.au> wrote in message
news:4084732e@newsgroups.borland.com...
> how do I tell it which entry from the registry I want logged
> in the event viewer.
By passing the actual custom codes as the reason when calling
ExitWindowsEx(), ie:
// reason codes are laid out as follows:
// 0xAABBCCCC
// AA = 8-bit flags
// BB = 8-bit major code
// CCCC = 16-bit minor code
// name these whatever you want...
#define MY_MAJOR_REASON_CODE 0x00400000 // 64 left-shifted 16
bits
#define MY_MINOR_REASON_CODE_0 0x00000000
#define MY_MINOR_REASON_CODE_1 0x00000001
#define MY_MINOR_REASON_CODE_2 0x00000002
ExitWindowsEx(
EWX_REBOOT,
SHTDN_REASON_FLAG_USER_DEFINED |
SHTDN_REASON_FLAG_PLANNED |
MY_MAJOR_REASON_CODE |
MY_MINOR_REASON_CODE_0);
To help make the code a little more readable, you can define some helper
macros that will generate a reason code from values you provide it:
#define MAKE_REASON_FLAGS(flags) \
(((DWORD)((BYTE)(flags))) << 24)
#define MAKE_REASON_MAJOR(major) \
(((DWORD)((BYTE)(major))) << 16)
#define MAKE_REASON_MINOR(minor) \
((DWORD)((WORD)(minor)))
#define MAKE_REASON_CODE(flags, major, minor) \
(MAKE_REASON_FLAGS(flags) | \
MAKE_REASON_MAJOR(major) | \
MAKE_REASON_MINOR(minor))
Then you can call it with hard-coded values:
ExitWindowsEx(
EWX_REBOOT,
MAKE_REASON_CODE(
SHTDN_REASON_FLAG_USER_DEFINED |
SHTDN_REASON_FLAG_PLANNED,
64,
0)
);
or use defines for the custom codes:
#define MY_MAJOR_REASON_CODE 64 // <-- not hex like above
#define MY_MINOR_REASON_CODE_0 0
#define MY_MINOR_REASON_CODE_1 1
#define MY_MINOR_REASON_CODE_2 2
ExitWindowsEx(
EWX_REBOOT,
MAKE_REASON_CODE(
SHTDN_REASON_FLAG_USER_DEFINED |
SHTDN_REASON_FLAG_PLANNED,
MY_MAJOR_REASON_CODE,
MY_MINOR_REASON_CODE_0)
);
As for the Registry, the only purpose of the Registry values is to set up
dialog flags and title/description information for the event loggers. When
you specify a reason code, ExitWindowsEx() decyphers what the specified
major and minor codes are and then looks up their cooresponding values in
the Registry for display/logging.
Gambit
Technical Details
Message-ID:
<4084916b$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!colt.net!diablo.netcom.net.uk!netcom.net.uk!newsfeed.wirehub.nl!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<4084732e@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,362cd189c238eed0 X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2004-04-19 20:09:34 PST From: "Remy Lebeau \(TeamB\)" <gambit47.no.spam@no.spam.yahoo.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <4084732e@newsgroups.borland.com> Subject: Re: Custom Shutdown Date: Mon, 19 Apr 2004 19:50:26 -0700 Lines: 84 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 67.22.138.253 Message-ID: <4084916b$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1082429803 67.22.138.253 (19 Apr 2004 19:56:43 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!colt.net!diablo.netcom.net.uk!netcom.net.uk!newsfeed.wirehub.nl!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail