Page 1 of 1

Calling Visual Prolog from C

Posted: 28 Mar 2014 13:45
by l_jam
Hello! I have a programme written in Visual Prolog that I would like to use with a robot that understands only C. How can I call a Visual Prolog programme from C?

Posted: 28 Mar 2014 14:25
by Thomas Linder Puls
I suppose that you want to do more than just start the Visual Prolog program?

Which interaction do you want/need between the two programs?
Do you have the sources for the Visual Prolog program or just the program?

Posted: 28 Mar 2014 16:02
by George

Re:

Posted: 28 Mar 2014 18:53
by l_jam
Thomas Linder Puls wrote:I suppose that you want to do more than just start the Visual Prolog program?

Which interaction do you want/need between the two programs?
Do you have the sources for the Visual Prolog program or just the program?
The prolog program receives some input data (a .txt file), processes it, then returns the result (as a different .txt file). So, the C program has to send the input data to Prolog and then recieve the output from it.
I have all the sources.

Posted: 28 Mar 2014 19:44
by Thomas Linder Puls
l_jam wrote:
Thomas Linder Puls wrote:I suppose that you want to do more than just start the Visual Prolog program?

Which interaction do you want/need between the two programs?
Do you have the sources for the Visual Prolog program or just the program?
The prolog program receives some input data (a .txt file), processes it, then returns the result (as a different .txt file). So, the C program has to send the input data to Prolog and then recieve the output from it.
I have all the sources.
In that case, it is actually C problems not Visual Prolog problem:
  1. Write the data to the txt file
  2. Start the Visual Prolog program
  3. Wait for termination of the Visual Prolog program
  4. Read the resulting txt file
I believe it is number 2 and 3 that cause problems.

In Visual Prolog (in useExe and syncObject) 2 and 3 are implemented by means of:
  • CreateProcess which is not exactly the simplest function imaginable.
  • The last argument contains a process handle that can be used with for example WaitForSingleObject to wait for program termination.
But there may be other mwans awailable in your C libraries.

Posted: 29 Mar 2014 10:03
by l_jam
Thomas, George, thank you for your replies. I will try your advice.