|
I don't think that would be possible or easily possible.
Anyway, how do you think you will stop "pull the plug"?
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Thanks for the reply.
But I am not considering the case of CPU Power down or anybody plug off the power cable, UPS will take care these things.
But programaticaly if anybody trying forcefull shutdown or remote shutdown I want to delay the shutdown untill my application finish this work.
Another way I found AbortShutdown api but with this also i not able to get proper result or may be somewhere I am missing.
But If you have any idea to delay the shutdown, if anybody call ExitWindow with SW_FORCE please share it with me.
Thank you
abhi
|
|
|
|
|
Oops!
I appear to have misread your post. If you want to _prevent_ somebody from shutting down windows, you'll need to hook ShutdownWindowsEx & SetSuspendState (or to be more precise, the kernel ZwShutDownWindows or NTShutDownWindows or something like that, I forget.
This will allow you to process any requests to shut down the box before the O/S does. Then all you have to do is return an error code every time, whilst never actually shutting down/standing by or hibernating the box.
You want to do basically what SetWindowsHookEx will do, except you want to do it with calls to the functions that power windows down, instead of to the messages that are between windows . I think you'll find what you're after if you search for function hooks.
This is the sort of thing you want: http://www.bigwebmaster.com/2068.html[^], just make sure you find one that's being given away - there should be no need to pay.
[EDIT]:
See here for the answer:
Cached google copy of 'prevent EWX_FORCE' forum post[^]
modified on Wednesday, May 6, 2009 3:34 AM
|
|
|
|
|
bool shutDownWindows()
{
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
if (!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
return false;
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
&tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
(PTOKEN_PRIVILEGES)NULL, 0);
if (GetLastError() != ERROR_SUCCESS)
return false;
if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0))
return false;
return true;
}
bool standbyWindows()
{
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
if (!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
return false;
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
&tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
(PTOKEN_PRIVILEGES)NULL, 0);
if (GetLastError() != ERROR_SUCCESS)
return false;
if (!SetSuspendState(false, false, false))
return false;
return true;
}
|
|
|
|
|
Dear enhzflep,
Thanks for the reply.
But I want to avoid/prevent from the forcefull shutdown, not to make a shutdown.
Tahnk you,
abhi
|
|
|
|
|
If you're trying to do the impossible (like you are), that probably means that your design is incorrect.
In this case - I presume that you want to ensure that the system doesn't end up in an inconsistent state, by interrupting your activities? In that case, you need transactions[^] to enable you to make those operations atomic (i.e. they happen completely or not at all).
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Stuart Dootson wrote: If you're trying to do the impossible...
Really? I've seen the Visual Studio process refuse to be stopped when it was in the middle of something. Funny thing is, what it was in the middle of doing is why I wanted to stop it in the first place.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
DavidCrow wrote: I've seen the Visual Studio process refuse to be stopped
Heh - it won't get the chance to refuse to stop if I get at it pskill[^] can be your friend! I suspect that "shudown -lf" (which hte OP mentioned) is equally forceful
The point is that the OP was asking the wrong question - "how can I stop things interrupting my very important financial transactions" rather than "how can I design my system to be robust against interruptions when making important financial transactions".
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I have one MFC application which is working with some PCI boards.
I have been run this application for past one year without any problem. But now i got this error "MFC application has encountered a problem and need to close". What will be the reason for this problem?
help me to solve this one...
|
|
|
|
|
Your application crashed. If you want to fix the problem, you'll need to use the debugger to track down the problem.
|
|
|
|
|
Use WinDbg[Used to debug user-mode crash dumps.]. You can take a dump using the ProcessDumper at the point when your application crashes. Analyze the dump using Windbg and correct the problem. This tool can be handy when you are not certain about the point of crash and debugging seems to be a mammoth task.
You need to google first, if you have "It's urgent please" mentioned in your question.
_AnShUmAn_
|
|
|
|
|
i have MFC application tooo. but it working fine... DUDE.. you have to let people here know how exactly your application works, it would be better if you debug the code and find the point where you application actually failing
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
What's your os now and what was it previous?
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
|
ganesh.dp wrote: help me to solve this one...
It could be any number of reasons. Start here.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Hi all. Slightly tricky one here.
I have a template class that has more than one template argument, for example:
<br />
template< class X, int N ><br />
class Foo<br />
{<br />
public: <br />
int GetValue() const;<br />
};<br />
Now, say that I want to specialize GetValue so that it returns, say, 69 for a template argument of N = 5, but returns 42 for all other values of N. For example:
<br />
Foo< char, 3 > foo1;<br />
foo1.GetValue();
<br />
Foo< double, 17 > foo2;<br />
foo2.GetValue();
<br />
Foo< bool, 5 > foo3;<br />
foo3.GetValue();
One way that would work is to specialize the entire class for N = 5 and again for all other values, so as to provide two separate implementations of the class. For example:
<br />
template< class X, int N ><br />
class Foo<br />
{<br />
public:<br />
int GetNumber() const { return 42; }<br />
};<br />
<br />
template< class X ><br />
class Foo< X, 5 ><br />
{<br />
public:<br />
int GetNumber() const { return 69; }<br />
};<br />
But I want to avoid this approach because while it works well for this simple example class with only one function, I am in practice trying to specialize a member function on a much larger class with many functions that would be unchanged by the specialization. Thus, I need a method to specialize only the member function in question, without duplicating the rest of class Foo.
As far as I can determine, specializing the member function only works if it has a single template parameter, like so:
<br />
template< int N ><br />
class Foo<br />
{<br />
public:<br />
int GetNumber() const { return 42; }<br />
};<br />
<br />
template < int N ><br />
int Foo< N >::GetNumber() const { return 42; }<br />
<br />
template < ><br />
int Foo< 5 >::GetNumber() const { return 69; }<br />
Can anyone explain how I can apply this logic to the case of multiple template arguments? The following code, by way of example, does not compile.
<br />
template< class X, int N ><br />
class Foo<br />
{<br />
public:<br />
int GetNumber() const { return 42; }<br />
};<br />
<br />
template < class X, int N ><br />
int Foo< X, N >::GetNumber() const { return 42; }<br />
<br />
template < class X ><br />
int Foo< X, 5 >::GetNumber() const { return 69; }<br />
Any help would be greatly appreciated.
|
|
|
|
|
Why don't you simply make a check inside the function.
template< class X, int N>
class Foo
{
public:
int GetValue() const
{
return 5 == N ? 69 : 42;
}
};
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Jmuulian wrote: As far as I can determine, specializing the member function only works if it has a single template parameter, like so:
No, it's because it is fully specialised. The compiler will implicitly instantiate the class for that template parameter and specialise the method (see 14.7.3p4 of the 1998 C++ standard).
Jmuulian wrote: Can anyone explain how I can apply this logic to the case of multiple template arguments? The following code, by way of example, does not compile.
template< class X, int N >
class Foo
{
public:
int GetNumber() const { return 42; }
};
template < class X, int N >
int Foo< X, N >::GetNumber() const { return 42; }
template < class X >
int Foo< X, 5 >::GetNumber() const { return 69; }
These are attempted partial specialisations. Trouble is, the template parameters are on the class, not the method, so you have to partially specialise the class, not just the method. To do what you want, the compiler would have to implicitly partially instantiate the class template - it won't do that.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hi,
I have a requirement to open a .net application from within a C++ application. Can anyone of you please help me in this regard.
Thanks in advance.
Siva.
|
|
|
|
|
What do you mean by open an application?
If you want to execute a .NET executable, you can do so using CreateProcess .
If it is a DLL that you want to load, you will have to create a COM Callable Wrapper (CCW) for your .NET application and then use it within C++ just like it is a COM component.
Please refer to the documentation on CCW.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
if you have the binary you can use ShellExecute and for finer control use CreateProcess.
You need to google first, if you have "It's urgent please" mentioned in your question.
_AnShUmAn_
|
|
|
|
|
Hi everybody
In my application i want to receive some data and after reeving the data i have to perform some operation.
For the data to come it will take some 0 to 3 sec.
So i am using Sleep(3000) to wait the data to come.But some times the data will come in less than 1 second.So unnecessary i have to wait.
Before i was using this algorithm
While(dataHasNotCome)
{
//wait
}
But it failed as the data may not come sometimes and be in infinite loop.
I can use a counter and increment it till a particular value and stop the loop.
Other than that is there any other method.
Regards
Deepu
|
|
|
|
|
You can use asynchronous read here.
Since you have not mentioned how you are reading data, I will assume you can use the file manipulation functions on some sort of handle or you are using sockets.
If you are accessing a handle can use ReadFile or ReadFileEx with an OVERLAPPED structure.
For sockets you can use WSARecv function with an OVERLAPPED structure.
After calling the function you can wait on the event handle inside the OVERLAPPED structure.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
I am reading data from the COM port.It is happening in a thread and it keep on reading the data and this data is stored in one CMainFrame variable.
My part is to get this variable in my class and do some manipulations after the data has come.
The only thing i have to do is to check the data has come or not.
|
|
|
|
|
Open the port with the overlapped flag.
CreateFile(_T("COM1"), GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0);
Post the asynchronous read.
OVERLAPPED over = { 0 };
over.hEvent = ::CreateEvent(0, 0, 0, 0);
DWORD dwRead = 0;
ReadFile(m_hPort, buffer, len, &dwRead, &over);
Wait on the event for 3 seconds.
if (WAIT_OBJECT_0 != WaitForSingleObject(over.hEvent, 3000))
return;
GetOverlappedResult(m_hPort, &over, &dwReade, 0);
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|