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:

var sbmLib = CreateObject( "SBMLibrary" );
var path = "d:/powderhorn/Tools/ScriptTestTools/build/Release/Win32DllTest.dll"
sbmLib.SetLibraryName( path );
if ( !sbmLib.IsLibraryLoaded()) { 
	if ( ! sbmLib.LoadLibrary() ) {
		 Ext.WriteStream( "<font color=red><b> Test Failed: " +
		 "Unable to load library on </b>" );
		 Ext.WriteStream( path );
		 Ext.WriteStream( "</font>\r\n" );
	}
	else {
		Ext.WriteStream( "<b>Library load succeeded on ");
		Ext.WriteStream( path );
		Ext.WriteStream( "</b><br>\r\n" );
	}
}
else {
	Ext.WriteStream( "Library already loaded<br>" );
}