#2115 [ANN] Fancom :: Fantom / COM Automation Bridge

SlimerDude Fri 22 Mar 2013

In the spirit of "getting Fantom libraries out there" I thought I'd share Fancom.

http://repo.status302.com/doc/afFancom/

Fancom is a Fantom / COM Automation bridge for Fantom programs running on a JVM, using JACOB.

Yep, every language needs a wrapper around JACOB and I saw Fantom as being no different!

Overview

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

Usage

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 convert 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")

Events

You can register any class to receive events from a COM object by calling:

dispatch.registerForEvents(this)

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()

andy Fri 22 Mar 2013

Been awhile since I used Windows - but sounds cool ;)

SlimerDude Wed 27 Mar 2013

Following Fancom, I give you FancomSapi - Fancom Classes for Microsoft Speech API (SAPI) 5.4

http://repo.status302.com/doc/afFancomSapi

Making your computer speak couldn't be simpler than:

SpVoice().speak("It's time to kick ass 'n' chew bubble gum!")

and speech recognition is only a few lines more! See docs for examples.

Yep, every JACOB port needs a wrapper around SAPI and I saw Fancom as being no different!

Login or Signup to reply.