BBS: Inland Empire Archive Date: 12-23-92 (14:35) Number: 342 From: TONY ELLIOTT Refer#: NONE To: JEFF JOHNSTON Recvd: NO Subj: Re: errorlevels Conf: (2) Quik_Bas
JJ> re: FETCHERR.ZIP
JJ> I'd be interested in this also. Is it available to first time
JJ> callers? What about freq'ing?
It's relatively small, so if you have MASM 5.1, here you go. If not,
feel free to call. First time callers can download.
;-------------------------------Cut Here---------------------
; MonitorShell (MONSHELL.ASM)
; Written by Tony Elliott
; EllTech Development, Inc.
; 4374 Shallowford Industrial Parkway
; Marietta, GA 30066
; (404) 928-8960 Voice or (404) 928-7111 BBS (DS)
; Released into the public domain.
; This routine is written for Microsoft QuickBASIC 4.x,
BASIC 6.x and Microsoft
; PDS 7.x. Assemble using MASM 5.1: MASM MONSHELL;
; You can link it directly to your program, place it in a LINK library (.LIB)
; or a .QLB.
; To use it:
; DECLARE SUB MonitorShell ()
; DECLARE FUNCTION FetchErrorLevel% ()
;
; CALL MonitorShell
; SHELL "PkZip -Xxy"
; PRINT "ErrorLevel returned from SHELL:";FetchErrorLevel%
.model medium, basic
.code
Old21 Label Dword ;Label pointing to old Int 21h handler
Old21Offset dw ? ;Offset part
Old21Segment dw ? ;Segment part
MonitorSet db 0 ;Our "hooked" flag
ExitCode db ? ;Where we store the exit code
MonitorShell proc uses ds
; From BASIC: CALL MonitorShell
cmp cs:MonitorSet,0 ;Are we already hooked?
jnz MonitorExit ;If so, exit
mov ax,3521h ;Get current vector for int 21h
int 21h
mov cs:Old21Segment,es ;Remember it for later
mov cs:Old21Offset,bx
mov ax,2521h
push cs
pop ds ;Point int 21h handler to our code
mov dx, offset OurInt21
int 21h
mov cs:MonitorSet,-1 ;Set our flag
MonitorExit:
ret
OurInt21: ;Our Int 21h handler
cmp ah,4ch ;Is it a 'terminate' request?
jnz Continue ;If not, continue on
mov cs:ExitCode,al ;Remember the exit code
push ax
push ds
mov ax,2521h ;Unhook ourself after the first hit
mov ds,Old21Segment
mov dx,Old21Offset
int 21h ;Point Int 21h back to original handler
pop ds
pop ax
mov cs:MonitorSet,0 ;Set out flag back to zero
Continue:
jmp dword ptr [Old21] ;Transfer control to original Int 21h
MonitorShell endp
FetchErrorLevel proc
;From BASIC: DECLARE FUNCTION FetchErrorLevel%
; PRINT "Last errorlevel:"; FetchErrorLevel%
mov al,cs:ExitCode ;Put the errorlevel into al
xor ah,ah ;Zero ah
ret ;ErrorLevel returned as result
FetchErrorLevel endp
end
;--------------------------------Cut Here----------------------------
... My other vehicle is a Nova Class Starship ...
--- Blue Wave/Max v2.10 [NR]
* Origin: Oakland BBS - McDonough, GA - (404) 954-0071 (1:133/706.0)

Books at Amazon:
Back to BASIC: The History, Corruption, and Future of the Language
Hackers: Heroes of the Computer Revolution (including Tiny BASIC)
Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution
The Advent of the Algorithm: The Idea that Rules the World
Moths in the Machine: The Power and Perils of Programming
Mastering Visual Basic .NET