Home > Language Reference > Functions > System functions

LoadLibrary Function

Loads a shared library.

Syntax

Public Function LoadLibrary(ByRef sName as String, ByRef sType As String, ByRef sCreator As String) As Integer

ParameterDescription
sNameName of the library to load.
sTypeType of the library to load.
sCreatorCreator of the library to load.

Remarks

This LoadLibrary function loads the specified library by its name and possibly its type and creator. It then returns its reference number which should be used when calling functions into this library.

The function first checks if the requested library is already loaded by comparing the sName parameter to the list of loaded libraries. If this is the case, its reference number is returned. If not, the behavior of the function depends on the values of the sType and sCreator parameters.

If empty strings have been specified for these two parameters, the function does not attempt to load the requested library, and generates a runtime error to indicate that the library is not present. This syntax is usually used to access system libraries, like NetLib, which are preloaded when the PDA starts up for instance. For example:

Private iRefNum as Integer

Private Sub Button1_Click()
  Try
    iRefNum=LoadLibrary("Net.lib", "", "")
  Catch
    MsgBox "Built-in library NetLib not found"
  End Catch
End Sub

On the other hand, if a valid type and creator are specified, the function localizes the corresponding database and attempts to load it as a library. If the installation of this library succeeds, its reference number is returned otherwise a runtime error is generated. This syntax is normally used to access your own libraries. For example, to load MathLib (see the MathLib Sinus sample) :

Private iRefNum as Integer

Private Sub Button1_Click()
  Try
    iRefNum=LoadLibrary("MathLib", "libr", "MthL")
  Catch
    MsgBox "Can't find MathLib"
  End Catch
End Sub

Note: you must either specify empty strings or a valid type and creator for both the sType and sCreator parameters. If you specify an empty string for one of these two arguments, a runtime error will occur.

The RemoveLibrary function unloads a library. Always make sure that a library is not being used before unloading it. You can also refer to the shared libraries chapter in the Programmer's Guide for more information on developing shared libraries and communication between HB++ and C.

System requirements

SystemMinimal versionRemarks
Palm OSPalm OS 3.0-
Windows CEWindows CE 3.0-