Previous Section
6. How to use HIDE to code a DLL
| Contents | Next Section
Contents

7. How to use HIDE to write libraries



-Introduces the use of Namespaces.
-Shows how to use Compiler Settings to redirect output

- Create New Project:
Menu: Project > New Project
Type "DemoLib" in the "Project Name" field.
Select "Library" from "Project Type" group.
Click OK.
- Write the code for a library:

unit DemoLib;
#include ("DemoLib.hhf")

	procedure Lib.DemoProcedure;
	begin DemoProcedure;

		stdout.put("This is inside the DemoProcedure",nl);

	end DemoProcedure;

end DemoLib;
- Setup the header file:
Menu: Project > New File > Header
call it "DemoLib"
double-click on "Headers" in the Tree View.
If the Tree View is not visible, click View > Tree View first
double-click on "DemoLib.hhf" to open it in the editor.

DemoLib.hhf
#include ("stdlib.hhf")

namespace Lib;

	procedure DemoProcedure; @external ("LIB_DEMOPROCEDURE");

end Lib;
-Building the Project:
Click F5 to build it.
If you check the Projects\DemoLib folder, you should see the
DemoLib.lib file there.
-Redirecting Output:
In order to use the DemoLib.lib in your programs, you have to copy it into the hlalib folder and add it to your link list via menu:
Project > "Add To Link List"

In order to ease the process, HIDE allows you to redirect the output from a dialog option.

Select menu: Opton > Compiler Settings

You should see "DemoLib.lib" in the "Output Name" field. This is the default build name and the default location is the current project directory (Projects\Demolib\)

To have HIDE build the library directly in your hlalib folder, we have to move 2 directory levels back, and one forward to hlalib:

..\..\hlalib\DemoLib.lib

WARNING: Use this feature with caution as HIDE will overwrite any file that may share the same name in the target directory without warning.

Now select menu: Make > Rebuild All

If all went well, you should have "DemoLib.lb" in your hlalib folder.

In order to use this library, you must also copy the DemoLib.hhf header file somewhere where the program can use it. A convenient place is the hlainc folder or even hlainc\custom. For now, copy it to hlainc folder, just remember to delete this and the demolib.lib files after the demo as it is a useless library to keep!


-Testing the new Library:
Close this project : Project > Close Project
Start a new console project and call it TestLib


TestLib.hla

program TestLib;
#include ("DemoLib.hhf")

begin TestLib;

	call Lib.DemoProcedure;

end TestLib;

Now, before compiling this, make sure the "DemoLib.hhf" file is either in the TestLib folder or in hlainc folder.

Select menu: Procject > Add To Link List
From the dialog that pops up, go to the hlalib folder and select DemoLib.lib

To make sure it added properly, double click "Libraries" in the tree view. DemoLib.lib should be there.

Run It!
Menu: Make > Build & Run

If all went well, a console window will open displaying the text:

"This is from inside the DemoProcedure"

The use of Namespaces is optional and it is used here just for demonstration purposes.