# (Default) module

The **(Default)** module --- known internally as **\_HiddenModule** --- gathers together the unqualified intrinsic procedures that the compiler emits calls into and that are also callable directly: raw-memory helpers, atomic operations, compile-time reflection, codegen and stack-inspection primitives, and a long tail of runtime utilities. Members of this module are referenced without a qualifier, the same way **MsgBox** and **CStr** are.

Most of these procedures are deliberately hidden from IntelliSense and exist for advanced or low-level use; use them only when the higher-level alternatives in **[Math](/tB/Modules/Math/index.md)**, **[Strings](/tB/Modules/Strings/index.md)**, **[Information](/tB/Modules/Information/index.md)**, or **[Interaction](/tB/Modules/Interaction/index.md)** don't cover the case. Several have additional internal-only members that are not listed here at all.

The pointer functions [**ObjPtr**](/tB/Modules/Information/ObjPtr.md), [**StrPtr**](/tB/Modules/Information/StrPtr.md), and [**VarPtr**](/tB/Modules/Information/VarPtr.md) and the [**Array**](/tB/Modules/Information/Array.md) constructor are documented under the [**Information**](/tB/Modules/Information/index.md) module; [**Input**](/tB/Modules/FileSystem/Input.md), [**InputB**](/tB/Modules/FileSystem/InputB.md), and [**Width**](/tB/Modules/FileSystem/Width.md) under [**FileSystem**](/tB/Modules/FileSystem/index.md).

## Reading and writing memory

Memory at a known address is read and written one machine word at a time with the **GetMem*** / **PutMem*** family --- [**GetMem1**](/tB/Modules/HiddenModule/GetMem1.md), [**GetMem2**](/tB/Modules/HiddenModule/GetMem2.md), [**GetMem4**](/tB/Modules/HiddenModule/GetMem4.md), [**GetMem8**](/tB/Modules/HiddenModule/GetMem8.md), and [**GetMemPtr**](/tB/Modules/HiddenModule/GetMemPtr.md) for reads, with matching [**PutMem1**](/tB/Modules/HiddenModule/PutMem1.md), [**PutMem2**](/tB/Modules/HiddenModule/PutMem2.md), [**PutMem4**](/tB/Modules/HiddenModule/PutMem4.md), [**PutMem8**](/tB/Modules/HiddenModule/PutMem8.md), and [**PutMemPtr**](/tB/Modules/HiddenModule/PutMemPtr.md). [**vbaCopyBytes**](/tB/Modules/HiddenModule/vbaCopyBytes.md) and [**vbaCopyBytesZero**](/tB/Modules/HiddenModule/vbaCopyBytesZero.md) move blocks; [**AllocMem**](/tB/Modules/HiddenModule/AllocMem.md) and [**FreeMem**](/tB/Modules/HiddenModule/FreeMem.md) manage heap allocations. The pointer constructors that feed these helpers --- [**ObjPtr**](/tB/Modules/Information/ObjPtr.md), [**StrPtr**](/tB/Modules/Information/StrPtr.md), [**VarPtr**](/tB/Modules/Information/VarPtr.md) --- live in [**Information**](/tB/Modules/Information/index.md).

```tb check_build
Dim Buffer As LongPtr = AllocMem(16)
PutMem4 Buffer, &HDEADBEEF
Dim Magic As Long
GetMem4 Buffer, Magic
FreeMem Buffer
```

[**vbaRefVarAry**](/tB/Modules/HiddenModule/vbaRefVarAry.md) and [**vbaAryMove**](/tB/Modules/HiddenModule/vbaAryMove.md) are lower-level helpers used when interfacing with C-side array layouts.

## Object references and casting

[**vbaObjAddref**](/tB/Modules/HiddenModule/vbaObjAddref.md), [**vbaObjSet**](/tB/Modules/HiddenModule/vbaObjSet.md), and [**vbaObjSetAddref**](/tB/Modules/HiddenModule/vbaObjSetAddref.md) manipulate COM reference counts directly. [**vbaCastObj**](/tB/Modules/HiddenModule/vbaCastObj.md) returns the object reinterpreted as another COM interface, given its IID. [**CreateGUID**](/tB/Modules/HiddenModule/CreateGUID.md) generates a fresh GUID and returns it as a string.

## Atomic operations

The **Interlocked*** family wraps the corresponding Windows kernel atomics --- building blocks for lock-free counters and pointer swaps: [**InterlockedExchangePointer**](/tB/Modules/HiddenModule/InterlockedExchangePointer.md), [**InterlockedCompareExchangePointer**](/tB/Modules/HiddenModule/InterlockedCompareExchangePointer.md), [**InterlockedCompareExchange32**](/tB/Modules/HiddenModule/InterlockedCompareExchange32.md), [**InterlockedCompareExchange64**](/tB/Modules/HiddenModule/InterlockedCompareExchange64.md), [**InterlockedIncrement32**](/tB/Modules/HiddenModule/InterlockedIncrement32.md), and [**InterlockedDecrement32**](/tB/Modules/HiddenModule/InterlockedDecrement32.md).

## Compile-time reflection

A few intrinsics ask questions about the surrounding type without running anything; they are resolved by the compiler and embedded as constants. [**GetDeclaredTypeProgId**](/tB/Modules/HiddenModule/GetDeclaredTypeProgId.md), [**GetDeclaredTypeClsid**](/tB/Modules/HiddenModule/GetDeclaredTypeClsid.md), [**GetDeclaredTypeIid**](/tB/Modules/HiddenModule/GetDeclaredTypeIid.md), and [**GetDeclaredTypeEventIid**](/tB/Modules/HiddenModule/GetDeclaredTypeEventIid.md) report a type's COM identifiers. [**GetDeclaredMinEnumValue**](/tB/Modules/HiddenModule/GetDeclaredMinEnumValue.md) and [**GetDeclaredMaxEnumValue**](/tB/Modules/HiddenModule/GetDeclaredMaxEnumValue.md) return the minimum and maximum value of a declared enumeration.

## Codegen injection and stack inspection

[**Emit**](/tB/Modules/HiddenModule/Emit.md) and [**EmitAny**](/tB/Modules/HiddenModule/EmitAny.md) splice raw bytes or typed literals into the codegen output of the enclosing procedure --- the vehicle for inline assembly. [**StackOffset**](/tB/Modules/HiddenModule/StackOffset.md) and [**StackArgsSize**](/tB/Modules/HiddenModule/StackArgsSize.md) report layout information at the current call site; [**UnprotectedAccess**](/tB/Modules/HiddenModule/UnprotectedAccess.md) returns an object reference that bypasses the usual access checks on private members.

## Runtime expression evaluation

[**Eval**](/tB/Modules/HiddenModule/Eval.md) compiles and evaluates a twinBASIC expression supplied as a string, using a freshly built [**TbExpressionService**](/tB/Modules/TbExpressionService/index.md) configured with the standard library binder.

## Pictures, bitmaps, and icons

[**PictureToByteArray**](/tB/Modules/HiddenModule/PictureToByteArray.md) serialises an **IPicture** to a byte array; [**CreateStdPictureFromHandle**](/tB/Modules/HiddenModule/CreateStdPictureFromHandle.md) wraps a GDI handle in an **stdole.StdPicture**; [**ConvertIconToBitmap**](/tB/Modules/HiddenModule/ConvertIconToBitmap.md) does the obvious.

## Other helpers

[**GetInheritedOwner**](/tB/Modules/HiddenModule/GetInheritedOwner.md) returns the inherited owner object of a control. [**GetShortcutTextByEnum**](/tB/Modules/HiddenModule/GetShortcutTextByEnum.md) returns the localised display text for a built-in keyboard shortcut. [**SetThreadGlobalErrorTrap**](/tB/Modules/HiddenModule/SetThreadGlobalErrorTrap.md) registers a callback that fires when an unhandled run-time error escapes the active error handler chain on the calling thread.

Five members are declared **Hidden** and **Restricted**, so IntelliSense lists leave them out; twinBASIC's own packages call them. [**AddClassInstanceFlag**](/tB/Modules/HiddenModule/AddClassInstanceFlag.md) and [**RemoveClassInstanceFlag**](/tB/Modules/HiddenModule/AddClassInstanceFlag.md#removeclassinstanceflag) set and clear a flag on a class instance, and [**InternalGetReturnAddress**](/tB/Modules/HiddenModule/AddClassInstanceFlag.md#internalgetreturnaddress) returns the return address of the calling procedure. [**GetNameFromDispID**](/tB/Modules/HiddenModule/GetNameFromDispID.md) returns the name of the member that has a given dispatch ID, and [**ShowPropertyPageEditor**](/tB/Modules/HiddenModule/GetNameFromDispID.md#showpropertypageeditor) shows the property page that edits one property of a control.

## Members

- [AddClassInstanceFlag](/tB/Modules/HiddenModule/AddClassInstanceFlag.md) -- sets a flag on a class instance
- [AllocMem](/tB/Modules/HiddenModule/AllocMem.md) -- allocates a block of native memory and returns its address
- [ConvertIconToBitmap](/tB/Modules/HiddenModule/ConvertIconToBitmap.md) -- converts an icon picture to a bitmap picture
- [CreateGUID](/tB/Modules/HiddenModule/CreateGUID.md) -- generates a fresh GUID and returns it as a string
- [CreateStdPictureFromHandle](/tB/Modules/HiddenModule/CreateStdPictureFromHandle.md) -- wraps a GDI bitmap or icon handle in an **stdole.StdPicture**
- [Emit](/tB/Modules/HiddenModule/Emit.md) -- injects custom **Byte** values into the codegen stream of the enclosing procedure
- [EmitAny](/tB/Modules/HiddenModule/EmitAny.md) -- injects custom typed values into the codegen stream of the enclosing procedure
- [Eval](/tB/Modules/HiddenModule/Eval.md) -- compiles and evaluates a twinBASIC expression supplied as a string
- [FreeMem](/tB/Modules/HiddenModule/FreeMem.md) -- frees memory allocated with [**AllocMem**](/tB/Modules/HiddenModule/AllocMem.md)
- [GetDeclaredMaxEnumValue](/tB/Modules/HiddenModule/GetDeclaredMaxEnumValue.md) -- returns the maximum value of a declared enumeration type, resolved at compile time
- [GetDeclaredMinEnumValue](/tB/Modules/HiddenModule/GetDeclaredMinEnumValue.md) -- returns the minimum value of a declared enumeration type, resolved at compile time
- [GetDeclaredTypeClsid](/tB/Modules/HiddenModule/GetDeclaredTypeClsid.md) -- returns the COM CLSID associated with the declared type, resolved at compile time
- [GetDeclaredTypeEventIid](/tB/Modules/HiddenModule/GetDeclaredTypeEventIid.md) -- returns the COM event-interface IID associated with the declared type, resolved at compile time
- [GetDeclaredTypeIid](/tB/Modules/HiddenModule/GetDeclaredTypeIid.md) -- returns the COM interface IID associated with the declared type, resolved at compile time
- [GetDeclaredTypeProgId](/tB/Modules/HiddenModule/GetDeclaredTypeProgId.md) -- returns the COM ProgID associated with the declared type, resolved at compile time
- [GetInheritedOwner](/tB/Modules/HiddenModule/GetInheritedOwner.md) -- returns the inherited owner object of a control
- [GetMem1](/tB/Modules/HiddenModule/GetMem1.md) -- reads one byte from a memory address into a **Byte** variable
- [GetMem2](/tB/Modules/HiddenModule/GetMem2.md) -- reads two bytes from a memory address into an **Integer** variable
- [GetMem4](/tB/Modules/HiddenModule/GetMem4.md) -- reads four bytes from a memory address into a **Long** variable
- [GetMem8](/tB/Modules/HiddenModule/GetMem8.md) -- reads eight bytes from a memory address into a **Currency** variable
- [GetMemPtr](/tB/Modules/HiddenModule/GetMemPtr.md) -- reads a pointer-sized value from a memory address into a **LongPtr** variable
- [GetNameFromDispID](/tB/Modules/HiddenModule/GetNameFromDispID.md) -- returns the name of the member that has a given dispatch ID
- [GetShortcutTextByEnum](/tB/Modules/HiddenModule/GetShortcutTextByEnum.md) -- returns the localized text for a built-in keyboard shortcut by its enumeration ID
- [InterlockedCompareExchange32](/tB/Modules/HiddenModule/InterlockedCompareExchange32.md) -- atomically compares and exchanges a 32-bit value
- [InterlockedCompareExchange64](/tB/Modules/HiddenModule/InterlockedCompareExchange64.md) -- atomically compares and exchanges a 64-bit value
- [InterlockedCompareExchangePointer](/tB/Modules/HiddenModule/InterlockedCompareExchangePointer.md) -- atomically compares and exchanges a pointer-sized value
- [InterlockedDecrement32](/tB/Modules/HiddenModule/InterlockedDecrement32.md) -- atomically decrements a 32-bit value and returns the new value
- [InterlockedExchangePointer](/tB/Modules/HiddenModule/InterlockedExchangePointer.md) -- atomically exchanges a pointer-sized value and returns the previous value
- [InterlockedIncrement32](/tB/Modules/HiddenModule/InterlockedIncrement32.md) -- atomically increments a 32-bit value and returns the new value
- [InternalGetReturnAddress](/tB/Modules/HiddenModule/AddClassInstanceFlag.md#internalgetreturnaddress) -- returns the return address of the calling procedure
- [PictureToByteArray](/tB/Modules/HiddenModule/PictureToByteArray.md) -- serialises an **IPicture** into a **Byte** array
- [PutMem1](/tB/Modules/HiddenModule/PutMem1.md) -- writes one byte to a memory address
- [PutMem2](/tB/Modules/HiddenModule/PutMem2.md) -- writes two bytes to a memory address
- [PutMem4](/tB/Modules/HiddenModule/PutMem4.md) -- writes four bytes to a memory address
- [PutMem8](/tB/Modules/HiddenModule/PutMem8.md) -- writes eight bytes to a memory address
- [PutMemPtr](/tB/Modules/HiddenModule/PutMemPtr.md) -- writes a pointer-sized value to a memory address
- [RemoveClassInstanceFlag](/tB/Modules/HiddenModule/AddClassInstanceFlag.md#removeclassinstanceflag) -- clears a flag on a class instance
- [RuntimeCreateGetMessageHook](/tB/Modules/HiddenModule/RuntimeCreateGetMessageHook.md) -- creates an [**IGetMessageHook**](/tB/Modules/HiddenModule/index.md#igetmessagehook-interface) for filtering window messages
- [SetThreadGlobalErrorTrap](/tB/Modules/HiddenModule/SetThreadGlobalErrorTrap.md) -- registers a global callback invoked when an unhandled error is raised on the calling thread
- [ShowPropertyPageEditor](/tB/Modules/HiddenModule/GetNameFromDispID.md#showpropertypageeditor) -- shows the property page that edits one property of a control
- [StackArgsSize](/tB/Modules/HiddenModule/StackArgsSize.md) -- returns the total size, in bytes, of the arguments on the current procedure's stack frame
- [StackOffset](/tB/Modules/HiddenModule/StackOffset.md) -- returns the stack-frame offset of a variable
- [UnprotectedAccess](/tB/Modules/HiddenModule/UnprotectedAccess.md) -- returns an object reference that bypasses access checks on private members
- [vbaAryMove](/tB/Modules/HiddenModule/vbaAryMove.md) -- moves the contents of one array variable into another
- [vbaCastObj](/tB/Modules/HiddenModule/vbaCastObj.md) -- returns an object reinterpreted as another COM interface
- [vbaCopyBytes](/tB/Modules/HiddenModule/vbaCopyBytes.md) -- copies a block of bytes from one address to another
- [vbaCopyBytesZero](/tB/Modules/HiddenModule/vbaCopyBytesZero.md) -- copies a block of bytes from one address to another, then zeros the source
- [vbaObjAddref](/tB/Modules/HiddenModule/vbaObjAddref.md) -- increments the COM reference count of an object at a given address
- [vbaObjSet](/tB/Modules/HiddenModule/vbaObjSet.md) -- assigns an object pointer to an object variable, releasing any prior reference
- [vbaObjSetAddref](/tB/Modules/HiddenModule/vbaObjSetAddref.md) -- assigns an object pointer to an object variable, adding a reference and releasing any prior reference
- [vbaRefVarAry](/tB/Modules/HiddenModule/vbaRefVarAry.md) -- returns a pointer to the **SAFEARRAY** descriptor inside a **Variant** array

## IGetMessageHook interface

The **IGetMessageHook** interface hooks into the Windows message stream for a chosen window --- and optionally its descendants --- and forwards messages of a chosen type to a user-supplied callback. Obtain an instance with [**RuntimeCreateGetMessageHook**](/tB/Modules/HiddenModule/RuntimeCreateGetMessageHook.md); connect callbacks with [**RegisterMessage**](/tB/Modules/HiddenModule/RegisterMessage.md); then call [**Start**](/tB/Modules/HiddenModule/Start.md) to activate every registered subscription, and [**Stop**](/tB/Modules/HiddenModule/Stop.md) to remove them.

The interface inherits directly from **stdole.IUnknown** (it is not dispatch-based), and the callbacks supplied to **RegisterMessage** are typed as [**GetMessageHookHelper.GetMessageHandler**](#getmessagehandler).

```tb check_build inherits=Form
Const WM_LBUTTONDOWN = &H201

Sub Demo()
    Dim Hook As IGetMessageHook = RuntimeCreateGetMessageHook
    Hook.RegisterMessage Me.hWnd, AllDescendants, _
                         WM_LBUTTONDOWN, AddressOf OnLButtonDown
    Hook.Start
End Sub

Function OnLButtonDown(ByRef msg As GetMessageHookHelper.HookMSG) As LongPtr
    Debug.Print "Click at"; msg.pt.x, msg.pt.y
    ' Return zero to let the message continue normal processing.
End Function
```

### Members

- [RegisterMessage](/tB/Modules/HiddenModule/RegisterMessage.md) -- subscribes a callback to a single message type for a window and a chosen descendant scope
- [Start](/tB/Modules/HiddenModule/Start.md) -- activates every registered subscription
- [Stop](/tB/Modules/HiddenModule/Stop.md) -- deactivates every registered subscription

### EnumDescendantsModeFlags

Selects the window scope passed to [**RegisterMessage**](/tB/Modules/HiddenModule/RegisterMessage.md):

| Constant                                 | Value | Description |
|------------------------------------------|-------|-------------|
| **ExactWindow**{: #ExactWindow }         | 1     | Hook only the specified window. |
| **AllDescendants**{: #AllDescendants }   | 2     | Hook the specified window and every descendant --- children, grandchildren, and so on. |
| **DirectChildren**{: #DirectChildren }   | 4     | Hook the specified window and its immediate children only. |

## GetMessageHookHelper module

The **GetMessageHookHelper** module is a small companion to [**IGetMessageHook**](#igetmessagehook-interface) that holds the structures and the delegate type used by its callback. There is nothing to construct; the names exist only for use in declarations.

### HookMSG

A copy of the Windows `MSG` structure, passed by reference into a [**GetMessageHandler**](#getmessagehandler) callback.

```tb check_build
Type HookMSG
    hwnd As LongPtr             ' Window the message is destined for.
    message As Long             ' The WM_* identifier.
    wParam As LongPtr           ' Message-specific parameter.
    lParam As LongPtr           ' Message-specific parameter.
    time As Long                ' Time the message was posted, in milliseconds since system start.
    pt As HookPOINT             ' Cursor position when the message was posted.
End Type
```

### HookPOINT

A 2D point with **Long** coordinates, used by [**HookMSG**](#hookmsg) to hold the cursor position.

```tb check_build
Type HookPOINT
    x As Long
    y As Long
End Type
```

### GetMessageHandler

The callback signature accepted by [**IGetMessageHook.RegisterMessage**](/tB/Modules/HiddenModule/RegisterMessage.md). Returning zero generally lets the message continue normal processing.

```tb check_build
Public Delegate Function GetMessageHandler (ByRef msg As HookMSG) As LongPtr
```
