|
Using Visual Prolog DLLs from Other LanguagesVIP\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 LanguagesIf 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: Where Normally exported DLL functions in Win32 have <stdcall> modifier. So the declaration of the three predicates from the example above will look like: ExamplesThe examples are organized in subdirectories corresponding to the programming language: Borland Delphi main program using Visual Prolog DLLs.
Java (Microsoft and Sun) main program using a non-GUI Visual Prolog DLLs.
Microsoft Visual Basic main program using Visual Prolog DLLs
Microsoft Visual C++ main program using Visual Prolog DLLs
Notes about DLLsNo fail and no errors in exported predicatesPredicate, which is exported from DLL should be declared as procedure and all run time errors should be trapped by trap predicate. Exporting PredicatesThe 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 StackManaging 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 DLLDLL, which is built by Visual Prolog, can be linked to another project via import library or can be loaded dynamically in run time. |