|
View:
New views
2 Messages
—
Rating Filter:
Alert me
|
|
|
Calling YAP from C# codeHi 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 |
|
|
Re: Calling YAP from C# codeHi Daniel
Sorry again for the long delay. I sincerely hope this may still be useful :( On Fri, Apr 3, 2009 at 6:03 AM, Daniel Brandur Sigurgeirsson <danielbsig@...> wrote: > 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 I would suggest using printf in the YAP code. It is very primitive, I know. > 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. It should load from the current directory. What happens if you try running a goal like "nl". Does it succeed and generate output? > 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). I am actually impressed you can still build YAP with VC. I have been building YAP with icc but on Linux, on Windows I alway run off to mingw/cygwin. mingw should generate a lib file. > 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? It looked like your first approach was on the right track. My apologies Vitor > Daníel > ------------------------------------------------------------------------------ > > _______________________________________________ > Yap-users mailing list > Yap-users@... > https://lists.sourceforge.net/lists/listinfo/yap-users > > ------------------------------------------------------------------------------ Crystal Reports - New Free Runtime and 30 Day Trial Check out the new simplified licensign option that enables unlimited royalty-free distribution of the report engine for externally facing server and web deployment. http://p.sf.net/sfu/businessobjects _______________________________________________ Yap-users mailing list Yap-users@... https://lists.sourceforge.net/lists/listinfo/yap-users |
| Free embeddable forum powered by Nabble | Forum Help |