Carapace

COM Clients

With Carapace script, it is very easy to be a COM client. The following script fragment gains access to a COM server, in this case Microsoft's browser Internet Explorer.

    (create Dispatch "InternetExplorer.Application")
We use a dispatch interface to communicate with the Internet Explorer. Here we are using the ProgID (ie. the human-readable name) for the COM server. You can use the GUID if you wish ie. the following has the same effect of getting access to an (invisible) Internet Explorer instance:
    (create Dispatch "{0002DF01-0000-0000-C000-000000000046}")

If we expand the script fragment to store the dispatch interface:

    (global (::browser Dispatch))
    (set ::browser (create Dispatch "InternetExplorer.Application"))
then we can access properties and methods on this interface. For example, to see if the browser is visible:
    (print ::browser.visible)
This prints the symbol false if the browser is not visible. Now, to make it appear:
    (::browser.visible (quote true))
and to navigate to a page:
    (::browser.navigate "file://carapace.htm")

Connecting to Event Interfaces

COM servers can fire events -- for example, Internet Explorer fires an event when the navigation to a page is complete. It is useful to be able to receive these events and take the appropriate action.

Carapace connects an events interface on a COM server with a corresponding interface on the COM client using the comLink function. Once these two interfaces are connected, events can flow from the server to the client.

For a link to be successful, an inbound interface on the client must match an outbound interface on the server. In particular, the matching interfaces must have the same GUID.

Internet Explorer has an events interface called DWebBrowserEvents with id {EAB22AC2-30C1-11CF-A7EB-0000C05BAE0B}. By making a Carapace object with an inbound interface having this same id, this object can receive the events produced by Internet Explorer once they have been linked using comLink.


Contents Index Current topic: COM Related Links: Dispatch class, COM helpers, objects