About Importing a Type Library (AutoLISP/ActiveX)

Unlike many programming languages, you load a type library with AutoLISP at runtime rather than at compile time.

Note: ActiveX support in AutoLISP is limited to Windows only.

The vlax-import-type-library function is used to import a type library. When you import a type library, AutoCAD creates a set of wrapper functions that provide access to the application's methods and properties. The vl-load-com function is a helper function that loads the AutoCAD type library and wraps the functions it exposes with vla-.

When calling the vlax-import-type-library function, you must identify the type library and tell AutoCAD what prefixes to use in naming the wrapper functions for the application's methods and properties. Also which prefix for the application's constants. The vlax-import-type-library function takes the following syntax:

(vlax-import-type-library :tlb-filename filename [ :methods-prefix mprefix :properties-prefix pprefix :constants-prefix cprefix])

The filename argument is a string that names the type library. If you do not specify a path, AutoCAD looks for the file in the Support File Search Path.

The mprefix argument specifies the prefix to be used for method wrapper functions. For example, if the type library contains a Calculate method and the mprefix parameter is set to "cc-", AutoCAD generates a wrapper function named cc-Calculate. This parameter defaults to "".

The pprefix argument specifies the prefix to be used for property wrapper functions, and the cprefix argument defines the prefix to be used for constants contained in the type library. These parameters also default to "".

After importing the type library, you can use the Visual LISP Apropos feature to list the ActiveX wrapper functions resulting from the import. For example, enter mswm in the Apropos Options dialog box and select the Match by Prefix option to list all Microsoft Word ActiveX methods. Importing an application's type library enables you to use Visual LISP features such as Apropos on the application's properties and methods, but you can access the application even if you do not import its type library.

The following practices are recommended when using vlax-import-type-library:

Example

The following code imports a Microsoft Word type library, assigning the prefix mswm- to methods, mswp- to properties, and mswc- to constants:

(if (equal nil mswc-wd140Words) ; check for a Word constant
  (vlax-import-type-library
    :tlb-filename " C:/Program Files/Microsoft Office/Office14/msword.olb"
    :methods-prefix "mswm-"
    :properties-prefix "mswp-"
    :constants-prefix "mswc-"
  )
)