GetTIB Function

Purpose

Returns the linear address of a thread information block.

Syntax

x% = GetTIB()

Description

GetTIB() is generated as inline code and used to determine the linear address of a thread information block. A TIB contains the internal multitasking information of a thread. Because of the multitasking, a TIB cannot be stored in a Global (Public) or Static variable, only in a Local (register) variable is allowed. The structure of a TIB is almost undocumented, however the following variables of these block can be used.

{GetTIB()} is the address of the needed head of the list for the internal error handling. Used for Try/Catch/EndCatch in GFA-BASIC 32 respectively __try, __except/__finally in C.

{GetTIB() + 4} and {GetTIB() + 8} contain the maximum and minimum addresses of the stack.

{GetTIB() + 16} is GetCurrentFiber() and

{GetTIB() + 24} is a pointer to GetTIB() itself.

One possibility usage of GetTIB() is to check, if a program is running under a debugger. Under Windows 95/98 {GetTIB() + 32} is always zero if it runs under a debugger. To find out if Windows 95 or 98 is running use GetVersion(). Both highest bits of the return value are set, if it runs under Windows 95/98 (under Windows NT the highest bit is cleared).

Example

// This program was designed for OSs prior to WinMe & Win2000

If GetVersion() %& $c0000000 == $c0000000

If {GetTIB() + 32}

MsgBox "The program is running under a debugger"

Else

MsgBox "The program doesn’t run not under a debugger"

EndIf

Else

MsgBox "The program doesn’t run under Windows 95/98"

EndIf

Remarks

Since Windows NT 4.0 and Windows 98 there exists a function named IsDebuggerPresent, which offers exact this functionality.

Declare Function IsDebuggerPresent Lib "kernel32" () As Int

Try

If IsDebuggerPresent()

MsgBox "The program is running under" _

" a debugger"

Else

MsgBox "The program doesn’t run under" _

" a debugger"

EndIf

Catch // for Windows 95 and NT 3.51

If GetVersion() %& $c0000000 == $c0000000

If {GetTIB() + 32}

MsgBox "The program is running" _

"under a debugger"

Else

MsgBox "The program doesn’t run" _

" under a debugger"

EndIf

Else

MsgBox "Can’t find the function" _

" IsDebuggerPresent and the" _

"program doesn’t run under Windows 95"

EndIf

End Catch

See Also

GetCurrentFiber, GetFiberData

{Created by Sjouke Hamstra; Last updated: 07/10/2014 by James Gaite}