Phantom Documentation

[Help Home] [Phantom Home]
User Defined DLLs

Phantom supports limited use of user defined Dynamic Link Libraries (DLLs).  Functions written in C can be imported into the Phantom code by using the 'dll' statement.  Not all DLL functions can be called or loaded.  However, this feature provides an interface to complex user defined functions.

The syntax of a 'dll' statement is:

dll FuncName(string Dll_File, string Dll_Function, false, Return_Type, Parameter1, Parameter2, ....);


FuncName -  is the name of the function called in Phantom.  It can be the same name as the DLL function name.
string Dll_File - is the path and file name of the DLL.  This supports relative file names.
string Dll_Function - The name of the function exported from the DLL.
false - always false.  Included for future expandability.

Return_Type - The return type of the DLL function.  Can be 'bool', 'string', 'int', or 'void' (not 'rea'l). \

- The type (and optionally name) of the first parameter of the DLL function.  There can be up to 16 parameters.  The parameter types can be a 'string' ,'bool', or 'int'  (not 'real').

The DLL functions (written in C) can accept and return a char*, bool, or int.  The following example code is a C file compiled and built into a DLL using the Microsoft Visual C++ developer studio.

Example Code

// SampleDll.cpp  
// The 'extern "C" ' statement is required.

extern "C" {

        __declspec(dllexport) int DllAdd(int i1, int i2);

        __declspec(dllexport) int DllSub(int Num1, int Num2, int Num3);


__declspec(dllexport) int DllAdd(int Num1, int Num2)


        return Num1+Num2;


__declspec(dllexport) int DllSub(int Num1, int Num2, int Num3)


        return (Num1 - Num2 - Num3);


A DLL called 'SampleDll.dll' is created from this code with two functions, the DllAdd and the DllSub functions.  DllAdd returns an integer and accepts two integers.  DllSub returns an integer and accepts three integers.

These functions are called and loaded via the following Phantom script, assuming the DLL and the script are on the same directory

Example Code

#  Sample Script that uses DLLs

string Dir = "SampleDll.dll"; # The DLL file
int iRet;

# Load the DLL functions
dll DllFunc(Dir, "DllAdd", false, int, int i1, int i2);
dll DllSub1(Dir, "DllSub", false, int, int i1, int i2, int i3);

# Call the Functions iRet = DllFunc(1, 4);
iRet = DllSub1(iRet, 2, 4);

It is a good idea to review this sample and the use of DLLs before attempting to use this feature.

See Also: User Defined Functions

Copyright 2000-2011 Phantom Automated Solutions