Windows Mobile 6.5
A version of this page is also available for

This function loads and registers a typelib2 type library.

HRESULT LoadTypeLib( 
  OLECHAR FAR* szFile, 
  ITypeLib FAR* FAR* pptlib 


[in] Null-terminated string that contains the name of the file from which LoadTypeLib should attempt to load a type library.


[out] On return, a pointer to a pointer to the loaded type library.

Returns the HRESULT values shown in the following table.

Value Description




Out of memory.


One or more arguments is invalid.


The function could not write to the file.


The type library could not be opened.


The function could not read from the file.


The type library has an older format.


The LCID could not be found in the OLE-supported DLLs.


The type library or DLL could not be loaded.

Other return codes

All FACILITY_STORAGE errors can be returned.

Windows Embedded CE and Windows Mobile support only typelib2 type libraries. The LoadTypeLib function loads type libraries only from a resource; that is, from DLL or EXE files. It will not load foreign or stand-alone type library files.

The function LoadTypeLib loads a type library (usually created with MkTypLib) that is stored in the specified file.

If szFile specifies a file name with no path, LoadTypeLib searches for the file and proceeds as follows:

  • If the file is a stand-alone type library implemented by Typelib.dll, the library is loaded directly.
  • If the file is a DLL or an executable file, it is loaded.
    By default, the type library is extracted from the first resource of type ITypeLib.
    To load a different type of library resource, append an integer index to szFile, as in the following example:
    LoadTypeLib(C:\MONTANA\EXE\MFA.EXE\3, pptlib)
    This statement loads the type library resource 3 from the Mfa.exe file.
  • If the file is none of the above, the file name is parsed into a moniker (an object that represents a file-based link source), and is then bound to the moniker.
    This approach allows LoadTypeLib to be used on foreign type libraries, including in-memory type libraries. Foreign type libraries cannot reside in a DLL or an executable file.
    For more information on monikers, see the OLE Programmer's Reference in the Microsoft® Win32® SDK.

If the type library is already loaded, LoadTypeLib increments the type library's reference count and retrieves a pointer to the type library.

For backward compatibility, LoadTypeLib registers the type library if the path is not specified in the szFile parameter. LoadTypeLib will not register the type library if the path of the type library is specified. It is recommended that RegisterTypeLib be used to register a type library.

Passing invalid (and under some circumstances NULL) pointers to this function causes an unexpected termination of the application.

Windows Embedded CEWindows CE 2.0 and later
Windows MobileWindows Mobile Version 5.0 and later

Community Additions