How do you catch control-c in NT oci programs?
From: Chris Hafey <chafey_at_ecst.csuchico.edu>
Date: 1997/03/21
Message-ID: <5gumte$anc_at_charnel.ecst.csuchico.edu>#1/1
#include <windows.h>
#include <signal.h>
#include <iostream.h>
extern "C" {
}
return FALSE;
}
static void
sig_int(int signo)
{
}
return 0;
}
Date: 1997/03/21
Message-ID: <5gumte$anc_at_charnel.ecst.csuchico.edu>#1/1
Hello
Can someone please explain how to catch control C events in the Windows
NT platform? After I logon to the database with orlon(), my control-c
handler becomes disabled. I have tried both signal() and the Win32 specific
SetConsoleCtrlHandler() function. Note that my handler is called if
I am not logged into the database! Any ideas?
Oracle 7.3 oci libraries
Windows NT 4.0
MSVC 4.0
Console Application
Chris Hafey
#include <windows.h>
#include <signal.h>
#include <iostream.h>
extern "C" {
#include <oratypes.h> #include <ocidfn.h> #include <ociapr.h>
}
Lda_Def lda; ub1 hda[256];
BOOL HandlerFunc(DWORD ctrlChar)
{
switch(ctrlChar) {
case CTRL_C_EVENT:
cout << "Control-C caught" << endl;
return FALSE;
}
return FALSE;
}
static void
sig_int(int signo)
{
cout << "Control-C caught" << endl; exit(3); return;
}
int main(int argc, char **argv)
{
#ifdef USE_WIN32_HANDLER
if (SetConsoleCtrlHandler((PHANDLER_ROUTINE)HandlerFunc, TRUE) != TRUE) {
cout << "Can't set console control handler" << endl;
exit(1);
}
#else
if (signal(SIGINT, sig_int) == SIG_ERR) {
cout << "Can't catch SIGINT" << endl;
exit(2);
}
#endif
if (orlon(&lda, hda, (text *)"scott/tiger", -1, (text *) 0, -1, 0)) {
cout << "Logon failed" << endl;
} else {
cout << "Logon Success" << endl;
}
// Loop and wait for a control-c
while (1) {
Sleep(1000);
}
return 0;
}
-- chafey_at_ecst.csuchico.edu http://www.ecst.csuchico.edu/~chafeyReceived on Fri Mar 21 1997 - 00:00:00 CET
