SBM ModScript Reference → Additional SBM ModScript Features → Calling Functions in a DLL from SBM ModScript → Loading the Library in SBM ModScript
To load a DLL in SBM ModScript, you first need to create an SBM Library object using the CreateObject function call.
var sbmLib = CreateObject("SBMLibrary");
Once the object is created, tell the object which DLL you want to call functions in by calling SetLibraryName on the SBMLibrary object. You can specify the path in one of three ways.
Absolute path – You may specify an absolute path to the DLL that you wish to load. For example:
var path = "d:/ScriptTestTools/build/Release/Win32DllTest.dll"; sbmLib.SetLibraryName(path);
DLL name – You may specify the DLL alone and rely on the ScriptAppPath registry setting to find the library. The ScriptAppPath is a string value in the SBM home registry key that contains a semicolon-separated list of directories in which SBM should look for executables and DLLs that SBM ModScript will use. For example, if HKEY_LOCAL_MACHINE/Software/TEAMSHARE/TEAMTRACK/ScriptAppPath is set to "d:/ScriptTestTools/build/Release", the above example could be re-written as: sbmLib.SetLibraryName("Win32DllTest.dll");
For details on using ScriptAppPath, refer to Setting Script Application Paths.
DLL name without the extension – SBM ModScript also assumes an extension of .dll for any library name. Therefore, the above example could also be written as:
sbmLib.SetLibraryName("Win32DllTest");
Additionally, if you are going to use an absolute path to specify the library to load, you must also include the extension. The extension is not assumed when using an absolute path; it is only assumed if you are going to rely on the ScriptAppPath.
Once you have told the library object which library you want to load, call LoadLibrary to actually get the library loaded. For example:
sbmLib.LoadLibrary();
LoadLibrary() returns a boolean which indicates the success or failure of the operation. To avoid experiencing a runtime exception, always check the return value of LoadLibrary() prior to calling any functions in the DLL. For example:
if (sbmLib.LoadLibrary()){ sbmLib.CallLibraryFunction( "my_function" ); }
Copyright © 2007–2017 Serena Software, Inc. All rights reserved.