DECLARE FUNCTION name LIB "dll" ALIAS "#ordinal" (params) AS typeMGC_IMPORT_THUNK_BY_ORDINAL (import_table.c)Some Windows DLLs export functions by ordinal number rather than by name. V13 adds support for importing these via the # prefix in the ALIAS clause.
| Parameter | Description |
|---|---|
name | PB name used to call the function in your code |
"dll" | DLL filename (e.g., "kernel32.dll") |
"#ordinal" | Ordinal number prefixed with # (e.g., "#42") |
params | Parameter list (BYVAL/BYREF name AS type) |
type | Return type (LONG, QUAD, etc.) |
#COMPILE EXE
#DIM ALL
' Import by ordinal from kernel32.dll
DECLARE FUNCTION GetProcessHeapOrd LIB "kernel32.dll" _
ALIAS "#123" () AS QUAD
FUNCTION PBMAIN() AS LONG
LOCAL hHeap AS QUAD
hHeap = GetProcessHeapOrd()
PRINT "Heap handle: "; hHeap
FUNCTION = 0
END FUNCTION
; In .idata section:
; The PB declare name becomes the IAT symbol
; Linker registers it as MGC_IMPORT_THUNK_BY_ORDINAL
__imp_GetProcessHeapOrd:
dq IAT_GetProcessHeapOrd ; Import Address Table entry
; At link time, the PE import directory records:
; DLL: kernel32.dll
; Import by ordinal: 123
; Thunk: __imp_GetProcessHeapOrd
ALIAS "#123" and marks the declaration as ordinal importcall [__imp_<PBname>] as usualIMAGE_ORDINAL_FLAG set