code from www.snippets.org - not working 
Author Message
 code from www.snippets.org - not working

btw: I'm sure this is my error and not the authors.
I am trying to disable the use of ctrl-c and other hotkeys that could exit
my security program that runs at bootup on my win98 machine.  I found some
code on www.snippets.org that traps these hot-keys and prevents  them from
being executed.  Unfortunately, when I include this source with my own
source, even without any function calls to this source(just to make sure it
wasnt the way I was calling the functions) I get several parse errors. The
first is before the '*' in the following code.
static void (INTERRUPT FAR * oldkbisr)(void);
the second is before 'newkbisr'
static void INTERRUPT FAR newkbisr(void);
I tried removing FAR as suggested by someone else but I recieved the SAME
error. Keep in mind that this program is run in REAL DOS not console since
it is executed during bootup.  Although this error results during compile in
console as well.  All the snippets include files have been put in my include
dir, and Im using the current djgpp c compiler.  Below is the entire code
taken from snippets.org:
/* +++Date last modified: 05-Jul-1997 */

/*
**  KBTRAP.C - Traps Ctrl-Alt-Del, Ctrl-C, Ctrl-Break, SysRq, PrintScreen,
**             and Pause keys.
**
**  Derived from public domain sources, uses SNIPPETS header files
*/

#include <stdlib.h>
#include <dos.h>
#include "pchwio.h"
#include "sniptype.h"
#include "sniprint.h"

#define CTRLALT         (0x08|0x04) /* bit flags set in kbstat()        */
#define CTRL            (0x04)      /* bit flags set in kbstat()        */
#define ALT             (0x08)      /* bit flags set in kbstat()        */
#define DELSCAN         0x53        /* keyboard scan code for <Del>     */
#define CSCAN           0x2E        /* keyboard scan code for <C>       */
#define BREAKSCAN       0x46        /* keyboard scan code for <Break>   */
#define PRTSCRNSCAN     0x37        /* keyboard scan code for <PrtScrn> */
#define SYSREQSCAN      0x54        /* keyboard scan code for <SysReq>  */
#define MULTI2SCAN      0xE0        /* 1st byte of 2 byte scan code     */
#define MULTI3SCAN      0xE1        /* 1st byte of 3 byte scan code     */
#define KEYPORT         0x60        /* keyboard scan code port          */
#define CONTROLLERPORT  0x20        /* interrupt controller port        */
#define kbstat()        Peekw(0,0x417) /* BIOS data area - kb flags     */

#define keyport()      inp(KEYPORT)
            /* macro that returns the scancode of the key that caused   */
            /* the interrupt                                            */

#define install()      (oldkbisr=getvect(0x09),setvect(0x09,newkbisr))
            /* installation macro, installs newkbisr() in the keyboard  */
            /* interrupt chain                                          */

#define uninstall()       setvect(0x09,oldkbisr)
            /* removal macro, call to remove newkbisr() from interrupt  */
            /* chain.  oldkbisr()  must be removed before program ends  */

static void (INTERRUPT FAR * oldkbisr)(void);
            /* address of old keyboard ISR                              */

static Boolean_T PrtScrnPending = False_;
            /* semaphore to flag pending print screen operations        */

static void cleanup(void);
            /* atexit()-registered version of uninstall() macro         */

static Boolean_T KBtrap_active;
static Boolean_T KBtrap_installed = False_;

static void KBtrap(void);
static void cleanup(void);
static void INTERRUPT FAR newkbisr(void);

/*
**  Called to activate trapping the system keys. When called the first time,
**  it calls KBtrap() to install the ISR. Registers the ISR removal function
**  using atexit() so the ISR will always be uninstalled upon program
**  termination.
*/

void activate_KBtrap(void)
{
      if (!KBtrap_installed)
            KBtrap();
      KBtrap_active = True_;
#ifdef TEST
      puts("Keyboard trap activated");
#endif

Quote:
}

/*
**  Called to deactivate trapping the system keys, but leave ISR installed.
**  If the user had attempted a PrintScreen operation while the trap was
**  active, it is now called.
*/

void deactivate_KBtrap(void)
{
      KBtrap_active = False_;
#ifdef TEST
      puts("Keyboard trap deactivated");
#endif
      if (PrtScrnPending)
      {
            if (Success_ == PrtScrn())
                  PrtScrnPending = False_;
      }

Quote:
}

/*
**  Traps system keys - Ignores Ctrl-Alt-Del, Ctrl-C, Ctrl-Break, SysRq,
**                      and Pause.
**
**                      Defers execution of PrintScreen
*/

static void INTERRUPT FAR newkbisr(void)
{
      static int count = 0;
      int key = keyport();

      if (KBtrap_active)
      {
            if (count)
            {
                  unsigned char kbin;

                  --count;

                  if (PRTSCRNSCAN == key)
                        PrtScrnPending = True_;
IGNORE:
                  kbin = (unsigned char)inp(KEYPORT+1); /* reset keyboard
*/
                  outp(KEYPORT+1, kbin|0x80);
                  outp(KEYPORT+1, kbin);
                  disable();
                  outp(CONTROLLERPORT,0x20); /* tell controller to shut up
*/
                  enable();
                  return;
            }
            else switch (key)
            {
            case MULTI2SCAN:
                  count = 1;
                  goto IGNORE;

            case MULTI3SCAN:
                  count = 2;
                  goto IGNORE;

            case DELSCAN:
                  if (CTRLALT == (kbstat() & CTRLALT))
                        goto IGNORE;
                  break;

            case PRTSCRNSCAN:
                  PrtScrnPending = True_;
                  goto IGNORE;

            case CSCAN:
            case BREAKSCAN:
                  if (CTRL == (kbstat() & CTRL))
                        goto IGNORE;
                  break;

            case SYSREQSCAN:
                  goto IGNORE;
            }
      }
      else
      {
            if (count)
            {
                  --count;
                  return;
            }
      }
      oldkbisr();                         /* chain to old keyboard isr */

Quote:
}

static void KBtrap(void)
{
      install();
      atexit(cleanup);
      KBtrap_installed = True_;
#ifdef TEST
      puts("Keyboard trap installed");
#endif

Quote:
}

static void cleanup(void)
{
      uninstall();
#ifdef TEST
      puts("Keyboard trap uninstalled");
#endif
Quote:
}

--



Wed, 11 Sep 2002 03:00:00 GMT  
 code from www.snippets.org - not working

Quote:

>btw: I'm sure this is my error and not the authors.
>I am trying to disable the use of ctrl-c and other hotkeys that could exit
>my security program that runs at bootup on my win98 machine.

[snip]

This is rather platform-specific (C doesn't require the implementation
to have a keyboard, let alone Win98).  You'd be much better off asking
the clever people on a Windows group.

[ARGH!  Entirely right, and I should have pointed this out myself.  Allowing
 this answer in because readers will wonder otherwise. -mod]

--
Chris Mears


ICQ: 36697123

C-FAQ: http://www.eskimo.com/~scs/C-faq/top.html
--



Thu, 12 Sep 2002 03:00:00 GMT  
 code from www.snippets.org - not working


Quote:
>btw: I'm sure this is my error and not the authors.
>I am trying to disable the use of ctrl-c and other hotkeys that could exit
>my security program that runs at bootup on my win98 machine.  I found some
>code on www.snippets.org that traps these hot-keys and prevents  them from
>being executed.  Unfortunately, when I include this source with my own
>source, even without any function calls to this source(just to make sure it
>wasnt the way I was calling the functions) I get several parse errors. The
>first is before the '*' in the following code.
>static void (INTERRUPT FAR * oldkbisr)(void);
>the second is before 'newkbisr'
>static void INTERRUPT FAR newkbisr(void);
>I tried removing FAR as suggested by someone else but I recieved the SAME
>error. Keep in mind that this program is run in REAL DOS not console since
>it is executed during bootup.  Although this error results during compile in
>console as well.  All the snippets include files have been put in my include
>dir, and Im using the current djgpp c compiler.

[snip]

This code looks like it was written for 16 bit Borland or MS PC
compilers. These compilers recognize interrupt functions, and
change the entry and exit code for the function to save and
restore all registers, make them available to the function via
some interface or register pseudo-variables, and return from
interrupt at exit. They also allow 16 bit NEAR and 32 bit
segmented FAR function calls, whereas djgpp uses the 32 bit
protected mode linear address space for ALL functions.

The djgpp uses DPMI instead of straight DOS to do this, so you
have to run one of the DOS DPMI products at startup, available
wherever you got djgpp. You also have to program using the DPMI
facilities available in djgpp: read up on whether you can write
TSR or ISRs using djgpp, and how you will have to modify the code
to do so.

You can trap the break keys in djgpp by catching C signals: see
the library documentation for details.

Thanks. Take care, Brian Inglis         Calgary, Alberta, Canada
--

                                use address above to reply
--



Fri, 13 Sep 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. http://www.mvps.org/windev/cpp/class.html problem

2. http://www.ioccc.org/

3. www.HireAmericanCitizens.org

4. OT www.accu.org

5. WWW.GIWERSWORLD.ORG

6. www.faqs.org crisis

7. www.codeur.org

8. this code works on SGI does not work on linux

9. Visual Basic DAO35 code OK but C++ code not working

10. how to implement ORG masm code in VC ?

11. C++/ATL/ADO - Intellisense not working (statement completion options) not working

 

 
Powered by phpBB® Forum Software