SLL example

Below is a very simple example of a Static Link Library (SLL). This SLL unit module contains only one function that converts millimeters to inches.

#COMPILE SLL "conversion.sll"

#DIM ALL

FUNCTION MillimetersToInches(BYVAL mm AS DOUBLE) COMMON AS DOUBLE

FUNCTION = mm * 0.03937#

END FUNCTION

The #COMPILE SLL metastatement tells the compiler to create an SLL named conversion.sll.

By default, all procedures in PowerBASIC are private, which means they cannot be seen outside of the SLL. The COMMON keyword is used on the procedure definition line to indicate that the procedure is to be visible to the host application. If the COMMON keyword is not used in the procedure definition, the procedure will not be visible to the host application. If the MillimetersToInches function did not contain the COMMON keyword any attempt to reference it from a host program would result in a Missing Declaration error when the host program is compiled.

Below is a sample host program that links in the compiled conversion.sll into our program.

#COMPILE EXE

#DIM ALL

#LINK "conversion.sll"

FUNCTION PBMAIN () AS LONG

LOCAL Inches AS DOUBLE

LOCAL MilliMeters AS DOUBLE

MilliMeters = 1000.0#

Inches = MillimetersToInches(MilliMeters)

END FUNCTION

The #LINK metastatement is used to link the pre-compiled conversion.sll into our host program. Any procedure in the SLL that contains the COMMON keyword may be called by our host program. We call the MillimetersToInches function in the SLL just like any other function call.

See Also

What is an SLL?

Creating a Static Link Library