|
Btw, here is from doc.
Note
SIGINT is not supported for any Win32 application. When a CTRL+C interrupt occurs, Win32 operating systems generate a new thread to specifically handle that interrupt. This can cause a single-thread application such as one in UNIX to become multithreaded, resulting in unexpected behavior.
So terminating from Ctrl+C will not work. Try to kill process from task manager.
|
|
|
|
|
I used this code in release mode and killed it from the task manager, while running it from the command line so as to catch the text. - It never came.
Not quite sure what SIGINT has to do with the price of chewing-gum in Czechoslovakia? We're not trying to interrupt the process, we're just terminating it.
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <tchar.h>
void SignalHandler(int signal)
{
printf("Application aborting...\n");
}
int main()
{
typedef void (*SignalHandlerPointer)(int);
SignalHandlerPointer previousHandler;
previousHandler = signal(SIGABRT, SignalHandler);
getch();
abort();
}
However, now that I can't find the page that I lifted the above code from I can't help but get the feeling that this particular approach is an exercise that won't succeed. I reckon that the signal is only thrown when the _application_ calls abort(), and not when windows calls abort(theApp).
I wonder if you'd have to hook TerminateProcess or something similar. I've a feeling that such a solution will require a fairly hard-core answer. Good-luck
|
|
|
|
|
For console:
CTRL_CLOSE_EVENT or the Console process termination message.
If you close the console from Taskmanager's "End Task", then you get the CTRL_CLOSE_EVENT notification.
The CTRL_CLOSE_EVENT message is sent as a signal that a console application should terminate.
BUT
If you click on "End Process" from task manager, then there's no way to handle it, in .NET or Win32.
The code below displays the message "Signal to quit was received" once you click on "End Task" from task manager.
<code></code>
#define STRICT 1
#include <windows.h>
#include <ctime>
#include <iostream>
using namespace std;
bool GlobalQuit = false;
BOOL WINAPI CtrlHandler(DWORD fdwCtrlType) {
switch (fdwCtrlType) {
case CTRL_C_EVENT:
Beep(1000, 1000);
case CTRL_CLOSE_EVENT:
case CTRL_BREAK_EVENT:
case CTRL_LOGOFF_EVENT:
case CTRL_SHUTDOWN_EVENT:
system("Color 1A");
cout << "Signal to quit was received\n";
GlobalQuit = true;
return TRUE;
default:
return FALSE;
}
}
int main(int argc, char *argv[], char *envp[]) {
struct tm *today;
time_t ltime;
char *p;
SetConsoleCtrlHandler(CtrlHandler, TRUE);
while (!GlobalQuit) {
time(<ime);
today = localtime(<ime);
p = asctime(today);
Sleep(2000);
}
return 0;
}
modified on Friday, April 30, 2010 12:01 PM
|
|
|
|
|
The OP Doesn't want to terminate a process, he wants to INTERCEPT process termination in order to do cleanup. Please stop confusing the issue.
|
|
|
|
|
That will only work if the app has a message loop, and is still pumping messages
|
|
|
|
|
When Task Manager uses TerminateProcess() to end a process, there is no notification. Also, there are no notifications generated for WH_CBT hook procedures.
"One man's wage rise is another man's price increase." - Harold Wilson
"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
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Can't really be done folks. Task manager sends a WM_CLOSE or CTRL_CLOSE_EVENT first, but only if you terminate from the applications tab. You'll be able to intercept that one with the SetConsoleCtrlHandler function. Otherwise task manager will fire a TerminateProcess, which cannot be intercepted ever.
Read it from the master himself here.[^]
|
|
|
|
|
Hi,
The task manager uses two methods of terminating a process depending on which tab has been selected. The tab labled 'Applications' will send a WM_CLOSE message to the window when 'End Task' has been selected which can easily be intercepted and handled.
The task manager tab labled 'Processes' utilizes TerminateProcess[^] which cannot be intercepted/blocked by the target process.
Some useful documentation from Microsoft Windows Internals Fourth Edition[^]:
Processes, Threads, and Jobs[^]
Best Wishes,
-David Delaune
|
|
|
|
|
Hook SSDT ,but I think it is pretty difficlt
|
|
|
|
|
You could try and hook the TerminateProcess API.
But API hooking is not at all possible/recommended these days.
|
|
|
|
|
how do i check whether my submenu item is checked
|
|
|
|
|
<pre>
MENUITEMINFO info;
info.cbSize = sizeof (MENUITEMINFO); // must fill up this field
info.fMask = MIIM_STATE; // get the state of the menu item
VERIFY(submenu->GetMenuItemInfo(ID_HELP_TEST, &info));
if( info.fState == MF_CHECKED))
//
else
//
</pre>
This code will help.
|
|
|
|
|
|
If you check if it is checked then it is checked since you check it.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
|
I am having following code sample which uses fstream object to Read some buffered value and write the buffer at certain location in the another .cpp file. The code works perfectly i.e. It inserts the desired buffer at desired location. But if I try to open the output file to verify the logic, it opens like binary file(like dll) and not like normal CPP file in MSDEV. However it opens normaly in notepad. I am expecting it to open like normal CPP file in MSDEV.
fstream objFileStream(strFileName,(ios::out|ios::in|ios::nocreate),filebuf::sh_read);
while(objFileStream.getline(szBuffer,iCount,'\n')&&(bMoveToNextID==false))
{
strBuffer=szBuffer;
if((strBuffer.Find(strID))!=-1)
{
_tcscpy(szBuffer,strInsertText);
objFileStream.write(szBuffer,strInsertText.GetLength());
objFileStream.write("\n",3);
bMoveToNextID=true;
}
}
objFileStream.close();
modified on Friday, April 30, 2010 2:17 AM
|
|
|
|
|
varsha_vm wrote: fstream objFileStream(strFileName,(ios::out|ios::in|ios::nocreate|ios::binary),filebuf::sh_read);
You are using ios::binary, so of course the file is going to be opened in binary mode. Remove it to open in ASCII mode.
-Saurabh
|
|
|
|
|
Thanks for reply
But even if I remove the ios::binary, I am getting the same result. I don't have ios::binary in my original code. This is something I have tried when I was getting the undesired result. I have edited my original code sample.
|
|
|
|
|
varsha_vm wrote: objFileStream.write("\n",3);
This looks suspicious. Why 3?
"One man's wage rise is another man's price increase." - Harold Wilson
"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
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
David
Thanks for pointing out the error. I have added it for another new line, but removing it now. Program is working fine.
Thanks again.
|
|
|
|
|
Hi! I have a problem about release build
I'm using Visual Studio 2005. The project is worked on MFC
When I build the project what I working in debug mode, It builds done successfully.
but in release mode, Output window shows next
1>Compiling resources...
1>Linking...
1>Generating code
and then.. it doesn't pass.
It seems like be stoped.
After 20 min ,I just canceld build.
It has been built well before.
I just added some files(.h .cpp) and resorces(.bmp), not special code
and it happened.
one more thing,
if I set 'Off' at configuration 'Warnning Level', it builds succesffully.
What's involved in that?
Do you have any idea about that?
please help me
|
|
|
|
|
Try rebuild all, because it will delete all temporary files and start building your project fresh.
if doesn't work fine, could you please delete the "Release" folder and ncb files located in the project directory? If the project is too large, the linking may take long time.
-Sarath.
Rate the answers and close your posts if it's answered
|
|
|
|
|
I did it already.
but it doesn't work.
after that problem happend,
I found that all .obj files are made even .exe in 'Release' Folder.
.exe file size is 2MB ,excuting abnormally.
what the... T.T
|
|
|
|
|
Hi,
I found some code to play sounds. It works well but I can't figure out how to change the duration of the sound, e.g. to play for 100ms, 1000ms, 5000ms etc.
Here is the code. I added the DurationMillisecs parameter but I don't know how to utilize it.
BOOL Test1(long FREQUENCY, long DurationMillisecs)
{
#define BUFFERSIZE 4860 // 4k sound buffer
#define PI 3.14159265358979
HWAVEOUT hWaveOut;
WAVEFORMATEX WaveFormat;
WAVEHDR WaveHeader;
char Data[BUFFERSIZE];
HANDLE Done;
double x;
int i;
WaveFormat.wFormatTag = WAVE_FORMAT_PCM;
WaveFormat.nChannels = 2;
WaveFormat.wBitsPerSample = 8;
WaveFormat.nSamplesPerSec = 11025;
WaveFormat.nBlockAlign = WaveFormat.nChannels * WaveFormat.wBitsPerSample / 8;
WaveFormat.nAvgBytesPerSec = (WaveFormat.nSamplesPerSec * WaveFormat.nBlockAlign);
WaveFormat.cbSize = 0;
Done = CreateEvent (0, FALSE, FALSE, 0);
if (waveOutOpen(&hWaveOut,0,&WaveFormat,(DWORD) Done,0,CALLBACK_EVENT) != MMSYSERR_NOERROR)
{
MessageBox(0,"Sound card cannot be opened.", "error", 0);
return TRUE;
}
for (i=0; i < BUFFERSIZE; i++)
{
x = sin(i*2.0*PI*(FREQUENCY)/(double)WaveFormat.nSamplesPerSec);
Data[i] = (char)(127*x+128);
}
WaveHeader.lpData=Data;
WaveHeader.dwBufferLength=BUFFERSIZE;
WaveHeader.dwFlags=0;
WaveHeader.dwLoops=0;
if (waveOutPrepareHeader(hWaveOut,&WaveHeader,sizeof(WaveHeader)) != MMSYSERR_NOERROR)
{
Message("Error preparing Header!");
return TRUE;
}
ResetEvent(Done);
if (waveOutWrite(hWaveOut,&WaveHeader,sizeof(WaveHeader)) != MMSYSERR_NOERROR)
{
Message("Error writing to sound card!");
return TRUE;
}
if (WaitForSingleObject(Done,INFINITE) != WAIT_OBJECT_0)
{
Message("Error waiting for sound to finish");
return TRUE;
}
if (waveOutUnprepareHeader(hWaveOut,&WaveHeader,sizeof(WaveHeader)) != MMSYSERR_NOERROR)
{
Message("Error unpreparing header!");
return TRUE;
}
if (waveOutClose(hWaveOut) != MMSYSERR_NOERROR)
{
Message("Sound card cannot be closed!");
return TRUE;
}
CloseHandle(Done);
return FALSE;
}
void Message(LPCSTR msg)
{
MessageBox(0, msg, " ",0);
}
|
|
|
|
|
Duration(msec) / 1000.0 = durationSec
durationSec * samplesPerSecond = numOfSamplesRequired
for (i=0; i<numOfSamplesRequired; i++)
{
// ** Generate the sound wave based on FREQUENCY define
}
WaveHeader.dwBufferLength = numOfSamplesRequired * bytesPerSample
|
|
|
|