Keeping a Library Loaded Across Script Executions

For performance reasons, you may wish to keep a DLL loaded after your script has finished executing. That way the DLL is already loaded the next time the script executes. To do this, simply check to see if the library has been loaded by calling IsLibraryLoaded() before calling LoadLibrary(). If the library is not loaded, call LoadLibrary() to load it for the first time. As long as your script doesn't call FreeLibrary(), it remains loaded for the next time your script executes.

CAUTION:
If you plan to leave the library loaded, always check to see if the library is already loaded before calling LoadLibrary() to avoid loading the library multiple times. Technically the library is never loaded more than once. All subsequent calls to LoadLibrary() on an already loaded DLL result in a reference count being incremented. In general, it is not a good practice to call LoadLibrary() over and over without calling FreeLibrary().

For example:

Dim ttLib
Dim arg2
Dim path
Set ttLib = CreateObject( "TeamTrackLibrary" )
path = "d:/powderhorn/Tools/ScriptTestTools/build/Release/
Win32DllTest.dll"
ttLib.SetLibraryName( path )
if Not ttLib.IsLibraryLoaded()  Then
  If Not ttLib.LoadLibrary() Then
    Call Ext.WriteStream( _
      "<font color=red><b>Test Failed: Unable to load library " _
      & "on </b>" )
    Call Ext.WriteStream( path )
    Call Ext.WriteStream( "</font>\r\n" )
  Else
    Call Ext.WriteStream( "<b>Library load succeeded on ")
    Call Ext.WriteStream( path )
    Call Ext.WriteStream( "</b><br>\r\n" )
  End If
Else
  Call Ext.WriteStream( "Library already loaded<br>" )
End If