Subject: Re: [SWIPL] Extensions to ActiveX DLL

From: Paul Singleton <[email-masked]>
Date: Thu, 27 Sep 2001 14:47:37 +0100

Philip Warner wrote:

> Thanks to Douglas R. Miles, I now have the source for the ActiveX DLL for
> SWIPL; I would be interested in comments from anybody who has used (or
> considered using) the library. 

I considered using this, but concluded that the way it converted ActiveX 
data values (and object refs) to and from Prolog was inconsistent.

I spent a lot of time reimplementing it, but eventually gave up, 
deciding I was unlikely ever to finish it :-) (in any sense, but 
especially, produce something useful and memory-safe)

I came to realise, as should have been obvious to me, that any such 
interface requires clear goals, design and rationale.

Some suggested goals:

  * be able to create instances of (almost) any ActiveX object, and call 
(almost) any method

  * be able to represent, as a Prolog term, (almost) any ActiveX data 
value, preferably canonically, and convert to and from ActiveX 
representation without loss of information

  * handle callbacks and events (of limited use without these)

I say "almost" in case an incomplete but useful solution is feasible (I 
want to actually put this to use in commercial projects).

Here are some enhancements I attempted:

  * cooperative garbage collection of ActiveX object refs by linking to 
SWI-Prolog's atom garbage collection

  * avoid any use of SWI-Prolog "string" type (obsolescent)

  * handle arrays of more than one dimension, and with bounds other than 
zero

  * handle Variants and Arrays of Variants (containing anything)

Data conversions/representations:

  * String <-> atom

  * Boolean <-> @true, @false

  * Array(Type) <-> array(LoBounds,Type,ListOfList...OfType)

  * Date <-> date(Year,Mon,Day)+time(Hour,Min,Sec)

  * Currency <-> currency(Hi,Lo)

  * Variant.Empty <-> @empty

  * Variant.Null <-> @null

  * Variant.Decimal <-> decimal(Scale,Sign,Hi32,Mid32,Lo32)

  * Variant.Error <-> error(Severity,Facility,Code)

  * Nothing <-> @nothing

Miscellaneous issues:

  * what to do with ByRef parameters?

  * SWI-Prolog atoms are (in general) arbitrary, non-textual byte 
strings: conversion <-> String is not always appropriate

Eventually I decided it might be smarter to leverage Visual Basic 6.0, 
which supports CallByName and CreateObject, and is memory-safe, and 
catches all errors, but unfortunately it seems that calling VB6 from C 
is not properly supported (I found a Knowledge Base article which gave 
the very restricted circumstances in which it is safe, and gave up) 
(again :-).

I'd gladly hand over what I've done, but it's not clear where it should 
be going, or whether it can get anywhere sensible...

Paul Singleton