Dear Xailer users,
After Xailer 2 is possible to create DLLs, dynamic link libraries. As its name says, they are libraries that can be loaded on run time by the main application. When loaded, all its functions will be ready to use. The main benefit of the use of DLLs is that you can break any of your applications into different modules, so you can deliver only the modules you want and in case you need to send an update of the program you only need to send the modified or new modules.
The DLL libraries created by Xailer are libraries that only contain pcode (intermediate code) to be executed by the main application virtual machine. Therefore, this kind of libraries can only be used from programs written in Xailer.
The DLL libraries can have resources inside, like the main executable file. By default, the application will search for resources on the executable, but if the resource is not found, it will continue searching on all the loaded DLL libraries and in the same order they have been loaded.
To create a DLL library is necessary to indicate so on the Project properties dialog:
For the correct creation of the DLL is necessary the existence of the library XailerDLL.lib on the lib directory.
In order to access to any DLL function from the main application you must load the library with the function HB_LibLoad(
If you need to unload the library you may use the function HB_LibFree(
To access any function or class on that DLL library is necessary to indicate the compiler that the function will be loaded dynamically and you must the use the xHarbour DYNAMIC directive, in the same way you may use the REQUEST directive.
Here is a little sample showing its use:
DYNAMIC TFormInDLL ..... ..... //----------------------------------------- METHOD Button1Click( oSender ) CLASS TForm1 LOCAL nHandle nHandle := HB_LibLoad( "CodeInDll.dll" ) TFormInDLL():New(Self):ShowModal() HB_LibFree( nHandle ) RETURN Nil
You may find a complete sample of DLLs us on XailerSamplesDlls directory.
However, the use of DLL libraries have some limitations that you should know:
- Is possible that when you load the library with the function HB_LibLoad() the debugger message window is displayed showing you a list of functions not found. Obviously, this windows is only shown when executed from the IDE. This list of functions, it refers, to basic low level functions (written in ‘C’) that presumably will be used by the DLL, but they are missing (or not exported) on the main executable.In case this functions are called from code inside the DLL a GPF (general protection fault error) is automatically produced. The only way to avoid this problem is to force the link of those functions and the clasic REQUEST directive is not valid, since that only works for high level code. You must create dummy functions on the executable that call those missing functions. This limitation only afects to your own ‘C’ routines written on the DLL itself. If you have not created any low level function inside the DLL you will not have any problem, even if the message with the missing functions is shown.
- All the high level functions that you use inside the DLL must be linked on the main executable or developed on the library itself, on contrary you will receive the typical run time error message: ‘Function not found’. To force that all these functions get linked on the final executable you must use the xHarbour REQUEST directive.
- You may overload any PRG function that exists on the main executable but it will only be executed when its called from inside the DLL.
- You may overload more than once the same PRG function on more than one DLL, but on that case, from the main executable, only the first loaded function will be executed.
We had to upload a new version of Xailer for its correct performance and by the way we have fix all the bugs found on our last Xailer 2 distribution. The install file can be downloaded from the following link:
It requires also the same new version of xHarbour already published that can be downloaded from the following link:
We remind you that this version is only available to active registered users. For further information consult the article Xailer 2.0 news and enhancements on this same blog.