Navigation  without Java Scripts

Using Visual Prolog DLLs from Other Languages

VIP\FOREIGN\EXAMPLES directory contains a number of examples, all showing how to use Visual Prolog DLL’s from other languages.

All the examples use the same Visual Prolog DLL’s that are found in the DLLS directory, so these have to be compiled before any of the examples are compiled and run.

Common Notes for all Languages
Examples
Notes about DLLs

Common Notes for All Languages

If a string or a term is returned from the DLL to the calling program then the memory on GStack should be released. If for example a program calls an entry getString in a DLL, which returns a string, then the calling program should have the following structure:

dll_mark_gstack(Stack);
getString(String);
... // saving String in variable of calling program
dll_release_gstack(Stack);

Where dll_mark_gstack and dll_release_gstack are defined in (and exported from) the DLL as follows:

dll_mark_gstack(STACKMARK):- STACKMARK=mem_MarkGStack().
dll_release_gstack(STACKMARK):- mem_ReleaseGStack(STACKMARK).

Normally exported DLL functions in Win32 have <stdcall> modifier. So the declaration of the three predicates from the example above will look like:

global predicates
dll_mark_gstack(STACKMARK) - procedure (o) language stdcall
dll_release_gstack(STACKMARK) - procedure (i) language stdcall
getString(string Out) - procedure (o) language stdcall

Examples

The examples are organized in subdirectories corresponding to the programming language:

Borland Delphi main program using Visual Prolog DLLs.

NONGUI: Delphi project uses a non-GUI Visual Prolog DLL.
USEVPI: Delphi project uses a Visual Prolog DLL with VPI.

Java (Microsoft and Sun) main program using a non-GUI Visual Prolog DLLs.

MSVJ example: Microsoft Visual Java program which uses a non-GUI Visual Prolog DLL.
SunJava example: Sun Java program which uses a non-GUI Visual Prolog DLL.

Microsoft Visual Basic main program using Visual Prolog DLLs

NONGUI: Microsoft Visual Basic project uses non-GUI Visual Prolog DLL.
USEVPI: Microsoft Visual Basic project uses a Visual Prolog DLL with VPI.

Microsoft Visual C++ main program using Visual Prolog DLLs

NONGUI: Visual Prolog project with MSVC as main program that uses non-GUI Visual Prolog DLL.
USEVPI: Microsoft Visual C++ MFC project that uses a Visual Prolog DLL with VPI.
ActiveX: Microsoft Visual C++ MFC ActiveX project that uses a Visual Prolog DLL with VPI.

Notes about DLLs

No fail and no errors in exported predicates

Predicate, which is exported from DLL should be declared as procedure and all run time errors should be trapped by trap predicate.

Exporting Predicates

The predicates to be called from outside a DLL must be defined as GLOBAL PREDICATES, which use the stdcall calling convention.

The predicate names MUST be added to the EXPORT section of the DLLs .DEF file.

Managing the DLL's Global Stack

Managing the DLL's Global Stack is done by using the mem_MarkGStack and mem_ReleaseGStack predicates inside DLL or dll_mark_gstack and dll_release_gstack functions on each side of the "real" DLL call. Memory management predicates should be included into DLL if there is no output argument with memory allocation.

In the Visual Prolog DLL  these predicates are defined like this:

GLOBAL PREDICATES
PROCEDURE dll_mark_gstack(STACKMARK) - (o) language stdcall
PROCEDURE dll_release_gstack(STACKMARK) - (i) language stdcall
CLAUSES
dll_mark_gstack(STACKMARK):- STACKMARK=mem_MarkGStack().
dll_release_gstack(STACKMARK):-mem_ReleaseGStack(STACKMARK).  

Because mem_MarkGStack and mem_ReleaseGStack are part of the run-time library there are no clauses implementing them. Their definitions can be included if you select PDCRUNT in the Application Experts Other Tools Dialog.

Link the DLL

DLL, which is built by Visual Prolog, can be linked to another project via import library or can be loaded dynamically in run time.