In Visual Prolog you can state the link name in an "as" qualification to a predicate declaration: Different compilers use different link names by default, and many compilers have ways of specifying specific link names.
The link name (or export name) is the name used to identify the foreign code that you want to call. I will discuss calling convention and link names together because these are related in the sense that traditionally certain compilers use some calling convention together with some scheme for link names.
And if the deallocator is not the same as the allocator, the deallocator will also have to know how to deallocate the memory.Īll in all there are four key issues to care about when calling foreign code: Both the caller and the callee must agree on who allocates memory and who deallocates it, and on when this should happen. The last thing that must be dealt with is memory management. In other words the data representation' must be the same. The caller and the callee must agree on the calling convention.īut not only must the caller and the callee agree on how parameters, etc are transferred, it is also important that the caller and the callee both interpret the transferred bytes in the same way. Obviously the caller and the callee must agree on how this has to be done. There exists many different ways to perform this process. Next we have to pass input parameters and invoke the code and, when the code is executed, we have to retrieve output, and so forth. Now we have to code and we know where it is. In the sequel I will just use the term link name, for this concept. I write system, because sometimes the name you have to use does not appear in the code at all. Whether the name is called a link name or an export name makes no difference in the Visual Prolog code, but it may make a difference, when you are trying to find the name in the foreign code/system. If the code is located in a DLL you have to use the "export" name. If the code is linked directly into your program, the name you have to use is a "link" name. In this tutorial we are dealing with code, which is either linked directly into your own program, or which is located in a Dynamic Link Library (DLL). In order to use all foreign code you must of course have access to the code. I cannot setup strict limits, because it is very often possible to handle "impossible" cases if you are creative.
But it cannot call any such code the code will have to be "compatible".
Visual Prolog can (among other) call code, which is written in C and compiled with Microsoft's C compiler. So, for Visual Prolog to interact with foreign code, this code will have to behave in certain ways. It would be impossible for Visual Prolog to interact with all foreign code, simply because it is not possible to know the principles used by any other compiler. Foreign compilers do a number of things different than Visual Prolog, both because they are invented by different people, but also because they have to support the different natures of different languages.