Page 1 of 1

Need example of C function calling VIP DLL

Posted: 10 Jun 2021 9:02
by Rangarajan
Hi,
In the distributed examples, the "MyDll" example exports a function of type (string) -> (string), but that is consumed by another VIP program. How do I call this from a C/C++ program?

Thanks,
Rangarajan

Re: Need example of C function calling VIP DLL

Posted: 10 Jun 2021 14:17
by Thomas Linder Puls
You will use a vip-dll in the same way as you use other dll's.

Exactly how that is depends on you C++ system, and is really a question for some C++ forum.

But it involves declaring C++ pendants to the vip predicates and linking with the lib (or loading the DLL dynamically).

The predicate from the example:

Code: Select all

predicates     touch : (string String) -> string Touched language stdcall as "touch".
can (I guess) have a C++ declaration like this:

Code: Select all

extern "C" wchar_t* __stdcall touch(wchar_t* String);
extern "C" avoids name mangling of the link name.

Notice however that Visual Prolog strings (and other memory) are garbage collected and since the vip DLL cannot see which memory the C++ part references; memory will be garbage collected when it is no longer live from the vip part, even though the C++ part still references it (have it live).

Re: Need example of C function calling VIP DLL

Posted: 11 Jun 2021 1:31
by Rangarajan
Thank you!

Regards,
Rangarajan