Format:COM type library (TLB)
| Developer | Microsoft (OLE Automation) |
|---|---|
| Magic | 4D 53 46 54 ('MSFT') or 53 4C 54 47 ('SLTG') |
| Extensions | .tlb, .olb, .ocx, .dll (TYPELIB resource) |
| Endianness | little |
| On this wiki | Facts · Code · Notes · Topics |
OLE Automation type libraries: standalone .tlb files or TYPELIB resources inside PE files, in the newer MSFT format (magic 'MSFT', created by ICreateTypeLib2) or the older SLTG format (magic 'SLTG', ICreateTypeLib), plus the TypeLib registry keys that point to them.
Identification
A type library describes COM interfaces, coclasses, enums and structs (names, GUIDs, method signatures). It is a standalone file (.tlb, .olb) or the TYPELIB resource (resource type name "TYPELIB", resource id = the typelib index, usually 1) of a DLL, EXE or OCX. Wine loads the resource through FindResource(index, "TYPELIB") on a data-file mapping, falls back to NE files and to a plain file mapping, then reads the first four bytes: 0x5446534D ('MSFT' as bytes 4D 53 46 54) selects the MSFT parser and 0x47544C53 ('SLTG') the SLTG parser; anything else is refused. Wine's header comment: files created with ICreateTypeLib have 'SLTG', files created with ICreateTypeLib2 have 'MSFT'. Source: wine-mirror/wine dlls/oleaut32/typelib.c (TLB_ReadTypeLib, TLB_PEFile_Open) and typelib.h.
MSFT layout
Header (0x54 bytes, all int32 little endian): magic1 'MSFT', magic2 0x00010002, posguid (offset of the libid in the GUID table, -1 if none), lcid, lcid2, varflags (low nibble = SYSKIND; 0x41 typical, 0x51 with a help file, 0x151 with a help DLL), version, flags, nrtypeinfos (offset 0x20), helpstring, helpstringcontext, helpcontext, nametablecount (0x30), nametablechars, NameOffset, helpfile, CustomDataOffset (0x40), res44 (always 0x20), res48 (always 0x80), dispatchpos (HREFTYPE to IDispatch or -1), nimpinfos (0x50). After the header comes an array of nrtypeinfos int32 offsets of the type infos, then more per-type arrays, then the segment directory of 16 entries of 16 bytes (offset, length, -1, flags): TypeInfoTab (each type has a 0x64-byte MSFT_TypeInfoBase, 25 ints), ImpInfo, ImpFiles, RefTab, GuidHashTab (0x80 bytes), GuidTab, NameHashTab (0x200 bytes), Nametab, Stringtab, TypdescTab, ArrayDescriptions, CustData, CDGuids and two unknown entries. The exact order of the pieces between header and directory was Unverified for this page: read typelib.c ITypeLib2_Constructor_MSFT (starts near line 3457).
MSFT_TypeInfoBase starts with typekind (TKIND_ENUM 0, RECORD 1, MODULE 2, INTERFACE 3, DISPATCH 4, COCLASS 5, ALIAS 6, UNION 7 - Unverified, from the Microsoft TYPEKIND documentation), then posguid at 0x2C (index into the GUID table), flags at 0x30, NameOffset, version, cImplTypes and cbSizeVft (int16 each, at 0x4C and 0x4E) and size at 0x50. Names and strings are length-prefixed in the Nametab and Stringtab, which is why strings on a .tlb shows interface and method names.
HREFTYPE values: a reference is in this file when the low two bits are 0, and its type index is href divided by sizeof(MSFT_TypeInfoBase).
SLTG layout
SLTG_Header (packed): u32 magic 'SLTG', u16 nrOfFileBlks (number of block entries + 1), u16 res06 (always 9), u16 res08, u16 first_blk (1-based index of the first block), GUID guid (always 000204ff-0000-0000-c000-000000000046), u32 res1c (0x44), u32 res20 (0xFFFF0000). Block entries follow (u32 len, u16 index_string offset, u16 next); the order of blocks is found by starting at first_blk and following next. Then the 13 bytes '\x01CompObj' 'dir' (a trace of the compound-file stream names this format was derived from), nrOfFileBlks - 2 index strings of 11 bytes ('AAAAAAAAAA' with the first letter incremented) and 9 zero bytes pad. Unverified: SLTG is the older of the two formats and rare in current software; Wine reads both.
Registry mapping
A registered library is TypeLib\{libid}\<major>.<minor> (hex, e.g. 1.0, 2.a), with value FLAGS, HELPDIR, and subkeys <lcid>\win32 or win64 (or win16) whose default value is the path of the file (a trailing \<n> selects the TYPELIB resource index). Each interface registered from it has Interface\{iid}\TypeLib (default = libid, value Version) and ProxyStubClsid32; Wine's registration code writes the proxy CLSID {00020424-0000-0000-C000-000000000046} (PSOAInterface) for interfaces and dual interfaces and {00020420-0000-0000-C000-000000000046} (PSDispatch) otherwise. Source: dlls/oleaut32/typelib.c lines 238-250, 285-330, 560-600. Side-by-side manifests can redirect a libid to a file with a typelib element (Wine's tlibredirect_data).
Parsers and tools
Wine's oleaut32 (LGPL-2.1+) is the reference open parser; the same data is exposed through the documented ITypeLib/ITypeInfo interfaces (LoadTypeLib, LoadRegTypeLib, LoadTypeLibEx). Unverified: Microsoft's oleview and Python's comtypes / pywin32 readers dump a library in IDL form.
Related
Technique:Reading COM and WinRT code, Format:WinRT metadata (WinMD) (the WinRT counterpart, ECMA-335 based), Format:Compound File Binary (the older compound-file origin of the SLTG stream names, Unverified), Format:PE (Portable Executable).
Code & repositories
- https://github.com/wine-mirror/wine @
7298a818b79446bae153b8d5aa27235ab3703bf9· license: LGPL-2.1-or-later (declared by the contributor; GitHub's detector did not recognize COPYING.LIB)
Wine: dlls/oleaut32/typelib.c and typelib.h (MSFT and SLTG parsers), dlls/combase/combase.c (CLSID registry lookups), include/*.idl (IUnknown, IDispatch, IInspectable, IActivationFactory).
Tested on: source read, not run: source read, not run · checked 2026-10-18; last activity 2026-10-16