LoadLibrary Statement |
Version 7 |
Loads a DLL library.
LoadLibrary DllLibrary, sDLLFilePath
The LoadLibrary statement loads a DLL library. The first argument of the LoadLibrary is a DLL name symbol that previously inserted under submodule Libraries. The DLL name must be marked as public if the Load statement is called from external module. DLL can be any DLL including ATEasy DLL.
The LoadLibrary statement will first unload the DLL if loaded already and load one in the sDLLFilePath argument.
Unloading or Loading a DLL allows the application to switch the modules DLLs implementation with another DLL. This can be useful when creating generic driver of which implementation can be changed by replacing a DLL. The DLL should have similar exported functions and parameters (count, type and return value), while the implementation of the exported functions can be different.
ATEasy does not perform any check to verify that the newly loaded DLL has the same export function names, which is done when the DLL procedure is actually called. In addition ATEasy cannot perform a check to see if the DLL procedure being called has the same parameters count and type. Calling a DLL procedure with different number of arguments (as defined in ATEasy under libraries submodule) may result in run-time error or memory corruption. Special care must be taken when defining the ATEasy DLL procedure and parameters types to make sure it matches the actual DLL exported function.
The second argument sDLLFilePath can be relative or absolute path. If you enter a filename with no pathname (directory), then ATEasy uses the following searching rules in order (same ones used during Inserting DLL) :
The Windows directory.
The Windows system directory (the directory containing such system files as GDI.EXE).
The directories listed in the PATH environment variable.
If the DLL is failed to load because the file path is not valid or the file is not found or any other reason, a run-time error will be generated.
If LoadOnAccess DLL property is on (checked in the DLL property page), the DLL will be loaded when a DLL procedure is called .
When the LoadLibrary is called, the DLL reference count is incremented. For non-ATEasy DLL the DLL LibMain is called to notify that it is loaded. For ATEasy DLL OnInit (OnInit/OnInitSystem) events are called after the DLL is loaded and before a DLL procedure is called.
The following example loads the gxsw32 library from a file gxsw32.dll, and the file is searched according to the DLL searching rules:
LoadLibrary gxsw32, "gxsw32.dll"
The following example loads gxsw32 DLL of the specific location for the module MUX:
LoadLibrary MUX.gxsw, "c:\\gxsw32.dll"