|
How can a service tell if the system is rebooting or shutting down and powering down? there appears to be only one control code for both occurances.
Are there any entries in the registry?
Or any other way?
|
|
|
|
|
It's been a long time since I did any real work with Windows Services but after a quick check with MSDN your services event handler *should* receive a SERVICE_CONTROL_SHUTDOWN event when the system is being shutdown / rebooted.
For more information check out the HandlerEx[^] documentation.
Gavin Taylor
w: http://www.gavspace.com
-- modified at 12:04 Monday 20th February, 2006
|
|
|
|
|
Sorry, just re-read your question, if your looking for a way to differentiate between shutdown events your out of luck - it's 'by design'
Gavin Taylor
w: http://www.gavspace.com
|
|
|
|
|
are they not the same thing ?
a shut down is a reboot with a long delay before start up.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
Not if you are deciding whether to shut down the UPS or not !!!
|
|
|
|
|
<sarcasm>
I think you need to trap the WM_POWER_BUTTON_PUSHED message and handle that instead.
</sarcasm>
This sounds a bit like a chicken/egg thing. On startup, does the service actually try to start-up the UPS? Can the service distinguish whether the PC is running off the main or battery?
Chris Meech
I am Canadian. [heard in a local bar]
When I want privacy, I'll close the bathroom door. [Stan Shannon]
BAD DAY FOR: Friendly competition, as Ford Motor Co. declared the employee parking lot at its truck plant in Dearborn, Mich., off limits to vehicles built by rival companies. Workers have to drive a Ford to work, or park across the street. [CNNMoney.com]
Nice sig! [Tim Deveaux on Matt Newman's sig with a quote from me]
-- modified at 15:26 Monday 20th February, 2006
|
|
|
|
|
The senario we have is that at the end of the day the power for our labs are turned off. This is for safety reasons. However the PC are protected by UPSs. If someone shuts down their PC, but forgets to switch off the UPS then the alarm goes off!!! Yours truly then spends the next few minutes trying to find which UPS is still switched on.
The solution is to write a service that schedules the UPS to power down as it is told that Windows is shutting down. The UPS doesn't power down immediately. Instead you instruct the UPS firmware to shut down after a timeout.
The problem is that the service will get the same notification if the user asks the PC to reboot. The result is that midway through the boot up sequence the power disappears. Unfortunately the UPS shutdown can not be aborted.
Chris Meech wrote: On startup, does the service actually try to start-up the UPS?
Starting up the PC is not too much of a problem because the UPS auto starts when the AC is applied and the PC has its BIOS set to auto boot the PC.
Chris Meech wrote: Can the service distinguish whether the PC is running off the main or battery?
<smugness>
Yes it can. It interrogates it though its HID interface.
Chris Meech wrote: I think you need to trap the WM_POWER_BUTTON_PUSHED message and handle that instead.
It's called WM_ENDSESSION, but services don't receive Windows messages. Instead they receive control codes. Both the control code and the Windows message give no indication as to whether the PC is about to reboot.
What I was hoping was that there was some way that Windows could tell you that the PC was going to reboot and would therefore need some power. Be it a system call or a registry entry.
|
|
|
|
|
Is each PC on it's own UPS?
Chris Meech
I am Canadian. [heard in a local bar]
When I want privacy, I'll close the bathroom door. [Stan Shannon]
BAD DAY FOR: Friendly competition, as Ford Motor Co. declared the employee parking lot at its truck plant in Dearborn, Mich., off limits to vehicles built by rival companies. Workers have to drive a Ford to work, or park across the street. [CNNMoney.com]
Nice sig! [Tim Deveaux on Matt Newman's sig with a quote from me]
|
|
|
|
|
Chris Meech wrote: Is each PC on it's own UPS?
Yes, otherwise one PC shutting down would kill the power of any other PC connected to the UPS.
|
|
|
|
|
My ex-colleague and friend ask me for a implementation of itoa. He's preparing for an interview. I don't how it seems to you, but the company here tend to ask questions like that a lot. Well, I'm not prepare for it too, so I ask for google as usual. Although Its a little function, but I'm not gonna let the chance of study slip away!
char* itoa(long n, int base)
{
register char *p;
register int minus;
static char buf[36];
p = &buf[36];
*--p = '\0';
if (n < 0)
{
minus = 1;
n = -n;
}
else
minus = 0;
if (n == 0)
*--p = '0';
else
while (n > 0)
{
*--p = "0123456789abcdef"[n % base];
n /= base;
}
if (minus)
*--p = '-';
return p;
}
After a little study, I figured I know how it was implemented. But there's some thing I'm not sure I right about or why it was implementated the way it is.
First the statement
*--p = "0123456789abcdef"[n % base]; seems strange enough to me at the first glance, but I learned from the book that
"0123456789abcdef" is called "Character array literals", and "...the result of the quoted character array is its starting address in memory....". So add a array element reference operation behind it is same as reference that element at certain index.Is my interpretation right?
Second, why
static char buf[36]; , why not
static char buf[46] or
[56]; ?
|
|
|
|
|
LiYS wrote: static char buf[36];
its static because it is returning the pointer to that array, so it should be not be a local variable allocated on the stack.
Why 36? i feel its a safe enough buffer to store number of digits that the long could have.
-Prakash
|
|
|
|
|
The maximum number of characters to display a long is 34,
so they have a safe side of 2 bytes
since a long is 4 byte the maximum characters that can be use is 34 to
display it in a textual form
4 bytes x 8 bits (base 2) is 32 chars
1 char for the ending '\0'
1 char for the minus
gives 34 chars
BTW: The code isn't error prone
codito ergo sum
|
|
|
|
|
Hi
I am using ExpandEnvironmentStrings() to find the path of pst files of MS Outlook, and passing the string "%USERPROFILE%\\Local Settings\\Application Data\\Microsoft\\Outlook\\*" to ExpandEnvironmentStrings().
Now I want toknow that this path \\Local Settings\\Application Data\\Microsoft\\Outlook\\ is same for all the languages of windows
Please suggest me.
Thanks
|
|
|
|
|
|
Hi,
Can anybody tell me, "Is Reg.dll functions are not supporting Unicode data?". I have got some keys that is in written in Pseudo language. I am able to see the key correctly in windows registry but when i try to read it gives me key with question marks and some un-readable output. What is the reason? Also do let me know in case anybody has solution meanwhile i am searching for some equivalent DLL on net.
Thank you for your time.
Nishith
|
|
|
|
|
i want to make an OCR application & extract text from an image.
i am trying the following approach.
1) i can convert an image to PDF.
2) i can extract text from PDF.
So, theoretically, perhaps OCR is possible this way- to convert image to PDF & then convert the PDF into text & do whatever search operations you have to.
http://www.altimate.ca/flash/ocrdsktp.htmshows the above approach.
However, i can extract text from any normal pdf, it is not happening with a pdf that has been generated from an image.What things may i be missing?
Kindly Guide.
Ankush Mehta
|
|
|
|
|
Simply because your image will be recognized as an image within the pdf file. So you cannot extract text from an image.
From the link you gave us, they probably do character recognition inside their program.
|
|
|
|
|
Hi,
I want to add ATL support to an MFC extension DLL in VC++.
You know that VC++ can add ATL support to regular DLLs but does not add this support to MFC extension DLLs.
Is there any way to add ATL support to MFC extension DLLs.
Should I convert the MFC extension DLL to a regular DLL first?
|
|
|
|
|
I am wondering about what's the best and easiest way to strip trailing whitespace from every single file in a folder, recursively.
I want to write a program/script so that you pass in a folder name and it'll recursively go through all sub-folders and strips trailing whitespace from every single file.
Trailing whitespace includes:
1. whitespaces at end of text lines, strip whitespace but retain text
2. whitespaces on empty lines, strip whitespace but leave the empty line
|
|
|
|
|
kevingpo wrote: I want to write a program/script so that you pass in a folder name and it'll recursively go through all sub-folders and strips trailing whitespace from every single file.
Open the file. Set the file pointer to the end using SetFilePointer() . Read the character. If it is non-white, call SetEndOfFile() and close the file. Otherwise, read the previous character...
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
|
|
|
|
|
See following code:
main (....)
{
CString strPath = "*.*";
Trim (strPath);
}
void Trim (CString &strPath)
{
CFileFind Info;
CStdioFile File;
CString strRecord;
BOOL bLoop;
bLoop = Info.FindFile ((LPCTSTR)strPath, 0);
while (bLoop)
{
bLoop = Info.FindNextFile ();
if ( Info.IsDirectory ()
&& !Info.IsDots ())
{
CString strSub;
strSub = Info.GetFilePath ();
strSub += "\\*.*";
Strip (strSub);
}
else if ( !Info.IsDirectory ()
&& !Info.IsHidden ()
&& !Info.IsReadOnly ())
{
printf ("%s\n",(LPCTSTR)Info.GetFilePath ());
if (File.Open ((LPCTSTR)Info.GetFilePath (), CFile::modeReadWrite|CFile::typeBinary, NULL))
{
DWORD dwReadPosition = 0;
DWORD dwWritePosition = 0;
UINT nRecord = 0;
try
{
while (File.ReadString (strRecord))
{
dwReadPosition = File.GetPosition ();
strRecord.TrimRight ();
File.Seek (dwWritePosition, CFile::begin);
File.WriteString ((LPCTSTR)strRecord);
File.WriteString ("\r\n");
dwWritePosition = File.GetPosition ();
File.Seek (dwReadPosition, CFile::begin);
printf ("%d\r",++nRecord);
}
printf ("\n");
}
catch (CFileException *Exception)
{
Exception->Delete ();
fprintf (stderr,"\nError writing to file\n");
File.Close ();
exit (1);
}
File.SetLength (dwWritePosition);
File.Close ();
}
}
}
}
This code example expects you use MFC. If you don't, you will have to use the standard FILE * type of routines.
Good luck.
William
|
|
|
|
|
Can someone tell me how a '+' operation is internally handled by the compiler(if possible with an example). Meaning that if I say 5+10 wat happens internally and how the compiler handles it??
|
|
|
|
|
From what I understand, all a compiler does (MSVC for example) is to convert your source code into machine readable code called ASM. If you google around you can find many examples of this language, which in turn will give you a better idea of what is actually happening behind the scenes.
|
|
|
|
|
waldermort wrote: ...all a compiler does (MSVC for example) is to convert your source code into machine readable code called ASM.
Not quite. Assembly is just another language, although not as high-level as C. What the compiler and linker do is create machine code that matches the instruction set of the processor.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
|
|
|
|
|
On a very low level, you change the current in some transistors so that the resulting transistor combination of open and closed transistors is interpreted as 15 by your computer.
~RaGE();
|
|
|
|