« Return to Thread: Calling YAP from C# code

Calling YAP from C# code

by Daniel Brandur Sigurgeirsson :: Rate this Message:

Reply to Author | View in Thread

Hi all,

I'm one of those very few weird folks that would like to use YAP in a C# program, but I'm having some problems with that.

First, if I call YAP from C# using P/Invoke, I can call YAP_FastInit - it does not seem to give me any errors. However, when I want to call "consult" using the following code:

public void Consult( String strFileName )
{
String strCommand = String.Format( "consult('{0}')", strFileName );
int term = 0;
int goal = YAPWrapper.YAP_ReadBuffer( strCommand, ref term );
int result = YAPWrapper.YAP_RunGoal( goal );
if ( result == 0 )
{
throw new ArgumentException( "Error while trying to consult file " + strFileName );
}

I always get a 0 result from calling YAP_RunGoal. Any ideas why? Is there any way to figure out why running a goal doesn't work? (Any GetLastError function?) Note that I've tried various possibilities with the file name: full path with or without the extension, just the filename again with or without the extension etc.

I suspected that this could be because I'm using P/Invoke to call YAP functions, so I tried linking directly to YAP, but in order to do that I need a .lib file to link against. I could not find it in the download, so I tried building YAP from the instructions given, only using VS2008 instead of VS 6.0. But every time I run that version, I get an error saying that I'm trying to access protected memory, and this happens with the first function I'm calling (YAP_FastInit).

Finally, I tried calling the YAP function directly using ::LoadLibrary( "yap.dll" ) and ::GetProcAddress( hLib, "YAP_FastInit"), but the program I wrote that does that (a simple console program in C++), simply crashes without any warning whatsoever when I try this.

So, are there any ideas on how I can call YAP from a C# program?

DanĂ­el

------------------------------------------------------------------------------

_______________________________________________
Yap-users mailing list
Yap-users@...
https://lists.sourceforge.net/lists/listinfo/yap-users

 « Return to Thread: Calling YAP from C# code