[racket] ActiveX support
At Fri, 31 Aug 2012 15:50:46 +0200, heraklea at gmx.de wrote:
> I have an ocx-control and I would like to use it from Racket.
>
> Is it possible to bind this control in any way to Racket/Scheme?
I think the way to do that is to use IE as an ActiveX container.
Below is an example that starts the "MSCAL.Calendar" control. As you
can see, I didn't figure out how to tell IE that it should trust the
control (so there's an 8-second pause while I click to allow in IE),
but maybe this will be enough to give you some ideas.
----------------------------------------
#lang racket
(require ffi/com
xml
(only-in ffi/unsafe/com
;; This was supposed to be exported from
;; `ffi/com':
guid->string))
;; Write a temporary HTML to load into IE. (There must be a way
;; to do this without temporary files.)
(define f (make-temporary-file "~a.html"))
(with-output-to-file f
#:exists 'truncate
(lambda ()
(write-xexpr
`(html
(head (title "Demo"))
(body
(h1 "Demo")
(object ((class "object")
(CLASSID ,(format
"CLSID:~a"
(let ([s (guid->string
(progid->clsid "MSCAL.Calendar"))])
(substring s 1 (sub1
(string-length s)))))))))))))
;; Start IE and navigate to the temporary file
(define ie (com-create-instance "InternetExplorer.Application.1"))
(com-invoke ie "Navigate" (path->string f))
;; Show it:
(com-set-property! ie "Visible" #t)
;; Hack: wait for human to allow blocked content...
(sleep 8)
;; Extract the calendar object:
(define doc (com-get-property ie "Document"))
(define cal (com-get-property
(com-invoke (com-invoke doc "getElementsByTagName" "object")
"item"
0)
"object"))
(com-methods cal)
(com-invoke cal "AboutBox")