typelib libname guid vermajor.verminor [lcid] [flags]
typelib libname file [flags]
typelib libname
libname - name of type library. It can be any name that you want to use to identify the type library later in code.
guid - globally unique identifier of type library.
vermajor.verminor - major and minor version. Digits.
lcid - locale identifier. Integer constant. Default: 0 (neutral).
1 | load on demand. The type library will be loaded into memory only when actually needed. |
2 | global scope. Identifiers from this type library can be used anywhere without specifying libname. |
file - type library file.
To insert this statement, use the COM Libraries dialog (menu Tools -> COM Libraries).
Declares a registered type library.
Declares a type library from file. By default, is used the type library from the first resource in the file. To use other resource, append \ and resource index (e.g., "c:\abc.dll\2").
Makes identifiers from a previously declared type library available in the current macro or function without specifying libname. Also, if the type library is still not loaded, loads.
A type library usually contains information about one or more COM classes (coclasses) and associated interfaces. Also can contain other declarations, such as dll functions, constants and types. It makes programming easier, because you don't have to manually declare them (type, def, dll and interface statements). It is either separate file (.tlb, .olb) or part of the component (.dll, .exe, .ocx). Typically, OLE-Automation-enabled applications and ActiveX components provide type libraries.
If a type library is declared with global scope (flag 2), identifiers from it (types, constants, etc) can be used anywhere, without any special syntax. Otherwise use syntax libname.identifier, unless the type library is declared in the same macro/function. Also, when using libname.identifier syntax, the identifier is automatically declared and colored when typing or opening macro.
See also: sub-function attribute r, application folders.
If a type library cannot be loaded (file not found, not registered, etc), is generated error, and compilation stops. If you are not sure that the component exists on user's system, you can use #err to mute the error, compile alternative code or call a user-defined function. Even if flag 1 (load on demand) is set, #err function works: if function returns nonzero, error is not shown.
To see what is inside type libraries, you can download and istall a type library browser, such as Microsoft's OLE Object Viewer (free).
See also: ref declarations scope
typelib Word {00020905-0000-0000-C000-000000000046} 8.0 0x409 typelib mytypelib "c:\type libraries\mytl.tlb" Word.Application wa int i = mytypelib.MyFunction(0)