interface prolog with C#

2019-06-28 04:53发布

i try to interface C# with prolog i have used this link : enter link description here

i have added the SwiPlCs.dll as a reference to my project,then use the first code in the documentation

using System;
using SbsSW.SwiPlCs;


namespace HelloWorldDemo

{

class Program
{
    static void Main(string[] args)
    {
        //Environment.SetEnvironmentVariable("SWI_HOME_DIR", @"the_PATH_to_boot32.prc");
        if (!PlEngine.IsInitialized)
        {
            String[] param = { "-q" };  // suppressing informational and banner messages
            PlEngine.Initialize(param);
            PlQuery.PlCall("assert(father(martin, inka))");
            PlQuery.PlCall("assert(father(uwe, gloria))");
            PlQuery.PlCall("assert(father(uwe, melanie))");
            PlQuery.PlCall("assert(father(uwe, ayala))");
            using (PlQuery q = new PlQuery("father(P, C), atomic_list_concat([P,' is_father_of ',C], L)"))
            {
                foreach (PlQueryVariables v in q.SolutionVariables)
                    Console.WriteLine(v["L"].ToString());

                Console.WriteLine("all child's from uwe:");
                q.Variables["P"].Unify("uwe");
                foreach (PlQueryVariables v in q.SolutionVariables)
                    Console.WriteLine(v["C"].ToString());
            }
            PlEngine.PlCleanup();
            Console.WriteLine("finshed!");
        }
    }
}

}

but an exception always goes .. it's say that :

The specified module could not be found. (Exception from HRESULT: 0x8007007E

in the SWI-prolog they have say about this error:

If libswipl.dll or one of its dependencies could not found you will recive an error like System.IO.FileNotFoundException: Das angegebene Modul wurde nicht gefunden. (Ausnahme von HRESULT: 0x8007007E)

i have copied the libswipl.dll from the program bin to my bin/debug folder in my project but it still the same problem .

what i have to do ?? Thanks

标签: c# prolog
2条回答
Luminary・发光体
2楼-- · 2019-06-28 05:23

I had the same error, so i downloaded SwiPlCs_1.1.60301.0 & i changed the name of SwiPlCs64.dll to SwiPlCs.dll & i added it as a reference in Visual Studio & it worked :) PS: i'm using visual studio 2010 & windows 7 64 bits. Hope this helps :)

查看更多
forever°为你锁心
3楼-- · 2019-06-28 05:25

Have you declared SWI_HOME_DIR ? Should point towards c`\Program Files\pl

Interface with C# doesn't works with Windows 7 64 bits, Visual Studio 2010 professionnal. Seems to be a bug, Uwe Lesta should fix the bug soon.

查看更多
登录 后发表回答