Fancom is a Fantom / COM Automation bridge for Fantom programs running on a JVM. It uses JACOB to make native calls to COM libraries via JNI. Fancom features:
- Runs on x86 and x64 environments supporting 32 bit and 64 bit JVMs.
- Supports COM Events
- COM encapsulation through surrogates
- Clean and simple API
To run, Fancom requires the JACOB file to be part of your Fantom installation. In particular:
afFancom.pod/lib/java/jacob-XXX.zipneeds to be copied to the
FAN_HOME/lib/java/ext/folder and renamed to
afFancom.pod/lib/dotnet/jacob-XXX.dllneeds to be copied to the
Dispatch wraps a COM object (the IDispatch interface) and allows you to get / set properties and call methods on the component.
All parameters to and from Dispatch objects are encapsulated in Variant objects. A Variant holds a standard Fantom object (
Bool etc...) and converts it for usage by the COM object.
A simple example:
Dispatch outlook := Dispatch.makeFromProgId("Outlook.Application") Str version := outlook.getProperty(Variant("Version")).asStr
For ease of use, Fancom will convert all standard Fantom literals to Variants for you, so the last line could be written as:
version := outlook.getProperty("Version").asStr
(You can actually pass in any Fantom object as long as it looks like a Variant Surrogate.)
Variants that reference other COM objects may be converted to
Dispatch objects allowing chaining:
Dispatch objWord := Dispatch.makeFromProgId("Word.Application") Dispatch documents := objWord.getProperty("Documents").asDispatch documents.call("Open", "myEssay.doc")
You can register any class to receive events from a COM object by calling:
Then when the COM object fires an event Fancom will look for a matching method on your event sink. The method is the name of the event, prefixed with
on. For example, if the event is called
FalseRecognition your handler method should be called