Discussions related to Visual Prolog
Rangarajan
Posts: 12
Joined: 1 Jun 2007 14:51

Need example of C function calling VIP DLL

Unread post 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
User avatar
Thomas Linder Puls
VIP Member
Posts: 1398
Joined: 28 Feb 2000 0:01

Re: Need example of C function calling VIP DLL

Unread post 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).
Regards Thomas Linder Puls
PDC
Rangarajan
Posts: 12
Joined: 1 Jun 2007 14:51

Re: Need example of C function calling VIP DLL

Unread post by Rangarajan »

Thank you!

Regards,
Rangarajan
Post Reply