Microsoft KB Archive/69159

= Example of How to Call Basic SetUEvent from C; ON UEVENT GOSUB =

Article ID: 69159

Article Last Modified on 8/16/2005

-

APPLIES TO


 * Microsoft Visual Basic for MS-DOS
 * Microsoft QuickBASIC 4.0b
 * Microsoft QuickBasic 4.5 for MS-DOS
 * Microsoft BASIC Compiler 6.0
 * Microsoft BASIC Compiler 6.0b
 * Microsoft BASIC Professional Development System 7.0
 * Microsoft BASIC Professional Development System 7.1

-



This article was previously published under Q69159



SUMMARY
Page 310 of the &quot;Microsoft Basic 7.0: Programmer's Guide&quot; states the following:

Trapping a user-defined event involves writing a non-Basic routine, such as in Microsoft Macro Assembler (MASM) or C, ....

On the same page, this statement is followed by an example of how to set up the ON UEVENT GOSUB routine in assembly language.

This article shows how the same example can be written in the Microsoft C language by using the SetUEvent function.



MORE INFORMATION
Use the following command to compile the C program listed below: CL -Od -AM -c uevent.c

Use the following command to compile the Basic program listed below: BC /O/V Basic.BAS; Link the programs together with the following command: LINK /NOE Basic+UEVENT, UEVENT.EXE; When the program is executed, the line &quot;Arrived here after 4.5 seconds&quot; will print every 4.5 seconds.

Note: The C program must be compiled with the medium memory model because the DS register must point to Basic's DGROUP space when SetUEvent is called.

Basic Code Example, Basic.BAS
' To try this example in VBDOS.EXE: ' 1. From the File menu, choose New Project. ' 2. Copy the code example to the Code window. ' 3. Press F5 to run the program.

DECLARE SUB SetInt DECLARE SUB RestInt ' Install new interrupt service routine: CALL SetInt ' Set up the Basic event handler: ON UEVENT GOSUB SpecialTask UEVENT ON DO ' Normal program operation occurs here. ' Program ends when any key is pressed. LOOP UNTIL INKEY$ <> &quot;&quot; ' Restore old interrupt service routine before quitting: CALL RestInt END ' Program branches here every 4.5 seconds: SpecialTask: ' Code for special task goes here, for example: PRINT &quot;Arrived here after 4.5 seconds&quot; RETURN

C Code Example, UEVENT.C
' To try this example in VBDOS.EXE: ' 1. From the File menu, choose New Project. ' 2. Copy the code example to the Code window. ' 3. Press F5 to run the program.

DECLARE SUB SetInt DECLARE SUB RestInt ' Install new interrupt service routine: CALL SetInt ' Set up the Basic event handler: ON UEVENT GOSUB SpecialTask UEVENT ON

DO ' Normal program operation occurs here. ' Program ends when any key is pressed. LOOP UNTIL INKEY$ <> &quot;&quot;

' Restore old interrupt service routine before quitting: CALL RestInt END

' Program branches here every 4.5 seconds: SpecialTask: ' Code for special task goes here, for example: PRINT &quot;Arrived here after 4.5 seconds&quot; RETURN

C Code Example, UEVENT.C
extern pascal SetUEvent;          // Define SetUEvent, which is in                                     // the Basic run-time library. void (_interrupt _far *OldInt) (void);   // The old interrupt vector. void _interrupt _far EventHandler (void);      // The UEVENT handler. char TimerTicks = 0;                     // Number of ticks elapsed.
 * 1) include 

void pascal SetInt                     // Set up the interrupts {                                        //   to point to the UEVENT OldInt = _dos_getvect(0x1C);         //    handler. _dos_setvect(0x1C, EventHandler); }

void interrupt EventHandler           // This is the UEVENT handler. {       if (++TimerTicks > 82)           // Check to see if 4.5 seconds {                                 //    has elapsed (18.2        TimerTicks = 0;                  //    ticks = 1 second). SetUEvent; }   _chain_intr(OldInt);                // Continue through old }                                      //    interrupt routine.

void pascal RestInt                  // Restore old interrupt {                                      //    when done to avoid _dos_ setvect(0x1C, OldInt);        //    conflicts after exit. }

Additional query words: VBmsdos QuickBas BasicCom 1.00 4.00 4.00b 4.50 6.00 6.00b 7.00 7.10

Keywords: KB69159

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.