Writing DLL's

Top  Previous  Next

Emergence BASIC can create DLL's for use in any language. A DLL is really just a collection of subroutines that are exported so other processes can use them.

The EXPORT statement

Creating the DLL is a simple as writing one or more subroutines adding an EXPORT statement for each subroutine that you want visible and compiling as a DLL target. In both project and single file mode the default extension is .dll and really should not be changed.

A simple DLL example:

export myfunction
export myfunction2
export INTRAND
 
SUB myfunction(in as INT),INT
RETURN in * 100
ENDSUB
 
SUB myfunction2(),INT
RETURN 0
ENDSUB
 
SUB INTRAND(min as INT,max as INT),INT
RETURN RAND(min,max)
ENDSUB

If you wish to use your newly created DLL with Emergence BASIC just create an import library for it as outlined in Using DLL's. The DLL must be either in your system directory or the executables directory.

When creating a DLL you can change the preferred load address, also know as the base address, by clicking on the "Advanced" button of the executable options or project options dialog.  Windows uses the base address to determine where to load the DLL and if your using more than one DLL with the same base address then conflicts can arise.

The default base address for DLL's is 0x10000000 hex.

Notes

If you wish your functions to use the CDECL calling convention, like that in the C runtime library, you must declare your function as in:
 

export INTRAND
DECLARE CDECL INTRAND(min as INT,max as INT),INT
SUB INTRAND(min as INT,max as INT),INT
RETURN RAND(min,max)
ENDSUB