Visual Prolog 7.0 Examples and Demos

How to Use Visual Prolog DLL from .Net

Written by Yuri Ilyin
Prolog Development Center

The example:

  1. creates a Visual Prolog DLL;
  2. shows how a program, created by Visual Basic .NET can call a predicate, exported by this DLL.

Main Issues

The two main issues should be considered, when using Visual Prolog  DLL from .Net:

  • Declaration of an invoked predicate in Visual Basic .NET;
  • Memory handling.

Declaration of an Invoked Predicate in Visual Basic .NET

Let us consider the declaration, used in this example.

Public Declare Unicode Function touch Lib "myDll"
     Alias "touch" (ByVal lpClassName As String) As String
  1. It is important to use Unicode statement, as Visual Prolog 6 uses Unicode for string arguments.
  2. The string after Alias "touch" should correspond to the definition in .DEF file, used in Visual Prolog 6 project.
EXPORTS
touch

Declaration of an Invoked Predicate in Visual C .NET

If it is necessary to declare the appropriate function in Visual C .NET, then the following declaration can be used.

[DllImport(@"myDll.dll", EntryPoint = "touch", CharSet=CharSet.Unicode)]
wchar_t* touch(wchar_t* lpClassName);
  1. It is important to use Unicode statement, as Visual Prolog 6 uses Unicode for string arguments.
  2. The string in EntryPoint "touch" should correspond to the definition in .DEF file, used in Visual Prolog 6 project.

Memory Handling

Visual Prolog 6 uses a garbage collector to free used memory, therefore special efforts are necessary to pass parameters to Visual Basic program.

The simplest way is to pass parameters, using COM memory, which is not freed by the  Garbage Collector.

The current example does this by invocation:

    basicString::toBstr

Another way is to allocate the memory in the .NET program, and pass a pointer to the Visual Prolog 6 DLL, so the Visual Prolog 6 DLL can use the predicate.

    memory::copy 

to fill data into this memory.

Download

Note

The example requires Visual Prolog 7.0 Commercial Edition, Build 7001 or higher.

If you use the Personal Edition, but need the  features supported only in the Commercial Edition, you are welcome to order the latest build of this Edition just now: Order!

Users of previous versions of Visual Prolog are welcome to upgrade to the current version of Visual Prolog  to use the latest versions of the Visual Prolog examples.

Examples for previous versions are still available.

 

Home | Company | News | Products Downloads | Shop | Support | Visual Prolog Features | Visual Prolog Compiler | FAQ | Tutorials | Examples | How to Migrate from Visual Prolog 5 to Visual Prolog 7 | Knowledge Base | Discussion Forum | wiki | Site Map
 

Prolog Development Center A/S - H.J. Holst Vej 3-5C - 2605 Broendby, Denmark - Tel +45 3636 0000 - Fax +45 3636 0001 - sales@visual-prolog.com