pod afFancom

A Fantom / COM Automation bridge for the JVM Runtime



A utility class that emulates a COM Collection object.


Handles the tricky business of COM threading.


Communicates to COM objects.


A Flag represents many states by setting and clearing bits on a Int.


A multi-format data type used for all COM communications.



As thrown by Fancom.


Thrown when a Dispatch call returns an VT_ERROR value


Thrown when a Dispatch call returns an invalid VT_HRESULT value


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


Fancom is centred around the Dispatch and Variant classes.

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 ( Int, Str, 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 onFalseRecognition()


To run, Fancom requires the JACOB file to be part of your Fantom installation. In particular:

  • afFancom.pod/lib/java/jacob-XXX.zip needs to be copied to the FAN_HOME/lib/java/ext/ folder and renamed to .jar
  • afFancom.pod/lib/dotnet/jacob-XXX.dll needs to be copied to the FAN_HOME/lib/dotnet/ folder

TODO: write a simple install script to copy the pod files

Release Notes



  • Added support for DateTime and Decimal Fantom types
  • Added support for more (lesser used) VT types
  • Dispatch.call now throws a FandocErr if a VT_ERROR or an invalid VT_HRESULT is returned
  • Added serialization ctor to Flag
  • Dispatch.call params could get mixed up if null was passed in
  • Surrogate diagnostics checks for typos and common ctor / static factory mixups


  • Initial release.