Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
A version of this page is also available for
4/8/2010

This function loads and registers a typelib2type library.

Syntax

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

Parameters

szFile

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

pptlib

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

Return Value

Returns the HRESULT values shown in the following table.

Value Description

S_OK

Success.

E_OUTOFMEMORY

Out of memory.

E_INVALIDARG

One or more arguments is invalid.

TYPE_E_IOERROR

The function could not write to the file.

TYPE_E_INVALIDSTATE

The type library could not be opened.

TYPE_E_INVDATAREAD

The function could not read from the file.

TYPE_E_UNSUPFORMAT

The type library has an older format.

TYPE_E_UNKNOWNLCID

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

TYPE_E_CANTLOADLIBRARY

The type library or DLL could not be loaded.

Other return codes

All FACILITY_STORAGE errors can be returned.

Remarks

Windows Embedded CE and Windows Mobile support only typelib2type libraries. The LoadTypeLibfunction 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 LoadTypeLibloads a type library (usually created with MkTypLib) that is stored in the specified file.

If szFilespecifies a file name with no path, LoadTypeLibsearches 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:

    Copy Code
    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 LoadTypeLibto 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 Referencein the Microsoft® Win32® SDK.

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

For backward compatibility, LoadTypeLibregisters the type library if the path is not specified in the szFileparameter. LoadTypeLibwill not register the type library if the path of the type library is specified. It is recommended that RegisterTypeLibbe used to register a type library.

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

Requirements

Header oleauto.h
Library oleaut32.lib
Windows Embedded CE Windows CE 2.0 and later
Windows Mobile Windows Mobile Version 5.0 and later

See Also