On this page:
5.9.1.1 GUIDs, CLSIDs, IIDs, and PROGIDs
guid?
clsid?
iid?
string->guid
string->clsid
string->iid
guid->string
guid=?
progid->clsid
clsid->progid
5.9.1.2 COM Objects
com-object?
com-create-instance
com-release
com-get-active-object
com-object-clsid
com-object-set-clsid!
com-object-eq?
com-type?
com-object-type
com-type=?
5.9.1.3 COM Methods
com-methods
com-method-type
com-invoke
com-omit
5.9.1.4 COM Properties
com-get-properties
com-get-property-type
com-get-property
com-set-properties
com-set-property-type
com-set-property!
5.9.1.5 COM Events
com-events
com-event-type
com-event-executor?
com-make-event-executor
com-register-event-callback
com-unregister-event-callback
5.9.1.6 Interface Pointers
com-object-get-iunknown
com-object-get-idispatch
com-iunknown?
com-idispatch?
5.9.1.7 Remote COM servers (DCOM)
5.9.1.8 COM Types
5.9.1.9 Class Display Names
com-all-coclasses
com-all-controls
coclass->clsid
clsid->coclass
5.9.1 COM Automation

The ffi/com library builds on COM automation to provide a safe use of COM objects that support the IDispatch interface.

The ffi/com library is based on the MysterX library by Paul Steckler. MysterX is included with Racket but deprecated, and it will be replaced in the next version with a partial compability library that redirects to this one.

5.9.1.1 GUIDs, CLSIDs, IIDs, and PROGIDs

(guid? v)  boolean?
  v : any/c
(clsid? v)  boolean?
  v : any/c
(iid? v)  boolean?
  v : any/c
Returns #t if v is a structure representing a GUID, #f otherwise. The clsid? and iid? functions are the same as guid?.

A GUID corresponds an a _GUID structure at the unsafe layer.

(string->guid str)  guid?
  str : string?
(string->clsid str)  clsid?
  str : string?
(string->iid str)  iid?
  str : string?
Converts a string of the form "{00000000-0000-0000-0000-0000000000}", where each 0 can be a hexadecimal digit, to a GUID. If str does not have te expected form, the exn:fail exception is raised.

The string->clsid and string->iid functions are the same as string->guid.

(guid->string g)  string?
  g : guid?
Converts a GUID to its string form.

(guid=? g1 g2)  boolean?
  g1 : guid?
  g2 : guid?
Determines whether g1 and g2 represent the same GUID.

(progid->clsid progid)  clsid?
  progid : string?
(clsid->progid clsid)  (or/c string? #f)
  clsid : clsid?
Converts a PROGID to a CLSID or vice versa. Not evey COM class has a PROGID, so the result of clsid->progid can be #f.

5.9.1.2 COM Objects

(com-object? obj)  boolean?
  obj : com-object?
Returns #t if the argument is a COM object, #f otherwise.

(com-create-instance clsid-or-progid [where])  com-object?
  clsid-or-progid : (or/c clsid? string?)
  where : (or/c (one-of/c 'local 'remote) string?) = 'local
Returns an instance of the COM class specified by clsid-or-progid, which is either a clsid or a progid.

The optional where argument indicates a location for running the instance, and may be 'local, 'remote, or a string indicating a machine name. See Remote COM servers (DCOM) for more information.

An object can be created this way for any COM class, but functions such as com-invoke work only if the object supports the IDispatch COM automation interface.

The resulting object is registered with the current custodian, which retains a reference to the object until it is released with com-release or the custodian is shut down.

(com-release obj)  void?
  obj : com-object?
Releases the given COM object. The given obj is subsequently unusable, and the underlying COM object is destroyed unless its reference count has been incremented (via COM methods or unsafe operations).

(com-get-active-object clsid-or-progid)  com-object?
  clsid-or-progid : (or/c clsid? string?)
Like com-create-instance, but gets an existing active object (always local) instead of creating a new one.

(com-object-clsid obj)  clsid?
  obj : com-object?
Returns the "clsid" of the COM class instantiated by obj, or raises an error if the COM class is not known.

(com-object-set-clsid! obj clsid)  void?
  obj : com-object?
  clsid : clsid?
Sets the COM clsid for obj to clsid. This is useful when COM event-handling procedures can obtain only ambiguous information about the object’s COM class.

(com-object-eq? obj1 obj2)  boolean?
  obj1 : com-object?
  obj2 : com-object?
Returns #t if the two COM objects are the same, #f otherwise.

(com-type? v)  boolean?
  v : any/c
Returns #t if v represents reflective information about a COM object’s type, #f otherwise.

(com-object-type obj)  com-type?
  obj : com-object?
Returns a representation of a COM object’s type that is independent of the object itself.

(com-type=? t1 t2)  boolean?
  t1 : com-type?
  t2 : com-type?
Returns #t if t1 and t2 represent the same type information, #f otherwise.

5.9.1.3 COM Methods

(com-methods obj/type)  (listof string?)
  obj/type : (or/c com-object? com-type?)
Returns a list of strings indicating the names of methods on obj/type.

(com-method-type obj/type method-name)
  (list/c '-> list? any/c)
  obj/type : (or/c com-object? com-type?)
  method-name : string?
Returns a list indicating the type of the specified method in obj/type. The list after the '-> represents the argument types, and the final value represents the result type. See COM Types for more information.

(com-invoke obj method-name v)  any/c
  obj : com-object?
  method-name : string?
  v : any/c
Invokes method-name on obj with vs as the arguments. The special value com-omit may be used for optional arguments, which useful when values are supplied for arguments after the omitted argument(s).

A constant for use with com-invoke in place of an optional argument.

5.9.1.4 COM Properties

(com-get-properties obj/type)  (listof string?)
  obj/type : (or/c com-object? com-type?)
Returns a list of strings indicating the names of readable properties in obj/type.

(com-get-property-type obj/type    
  property-name)  (list/c '-> '() any/c)
  obj/type : (or/c com-object? com-type?)
  property-name : string?
Returns a type for property-name like a result of com-method, where the result type corresponds to the property value type. See COM Types for information on the symbols.

(com-get-property obj property ...+)  any/c
  obj : com-object?
  property : string?
Returns the value of the final property by following the indicated path of propertys, where each intermediate property must be a COM object.

(com-set-properties obj/type)  (listof string?)
  obj/type : (or/c com-object? com-type?)
Returns a list of strings indicating the names of writeable properties in obj/type.

(com-set-property-type obj/type 
  property-name) 
  (list/c '-> (list/c any/c) 'void)
  obj/type : (or/c com-object? com-type?)
  property-name : string?
Returns a type for property-name like a result of com-method, where the sole argument type corresponds to the property value type. See COM Types for information on the symbols.

(com-set-property! obj string? ...+ v)  void?
  obj : com-object?
  string? : property
  v : any/c
Sets the value of the final property in obj to v by following the propertys, where the value of each intermediate property must be a COM object.

5.9.1.5 COM Events

(com-events obj/type)  (listof string?)
  obj/type : (or/c com-object? com-type?)
Returns a list of strings indicating the names of events on obj/type.

(com-event-type obj/type event-name)  (list/c '-> list? 'void)
  obj/type : (or/c com-object? com-type?)
  event-name : string?
Returns a list indicating the type of the specified events in obj/type. The list after the '-> represents the argument types. See COM Types for more information.

(com-event-executor? v)  boolean?
  v : any/c
Returns #t if v is a COM event executor, which queues event callbacks. A COM event executor com-ev-ex is a synchronizable event in the sense of sync, and (sync com-ev-ex) returns a thunk for a ready callback.

Creates a fresh COM event executor for use with com-register-event-callback.

(com-register-event-callback obj    
  name    
  proc    
  com-ev-ex)  void?
  obj : com-object?
  name : string?
  proc : procedure?
  com-ev-ex : com-event-executor?
Registers a callback for the event named by name in obj. When the event fires, an invocation of proc to event arguments (which depends on obj and name) is queued in com-ev-ex. Synchronizing on com-ev-ex produces a thunk that applies proc to the event arguments and returns the result.

Only one callback can be registered for each obj and name combination.

Registration of event callbacks relies on prior registration of the COM class implemented by "myssink.dll" as distributed with Racket. (The DLL is the same for all Racket versions.)

(com-unregister-event-callback obj name)  void?
  obj : com-object?
  name : string?
Removes any existing callback for name in obj.

5.9.1.6 Interface Pointers

(com-object-get-iunknown obj)  com-iunkown?
  obj : com-object?
(com-object-get-idispatch obj)  com-idispatch?
  obj : com-object?
Extracts an IUnknown or IDispatch pointer from obj. The former succeeds for any COM object that has not been relased via com-release. The latter succeeds only when the COM object supports IDispatch, otherwise exn:fail is raised.

(com-iunknown? v)  boolean?
  v : any/c
Returns #t if v corresponds to an unsafe _IUnknown-pointer, #f otherwise. Every COM interface extends IUnknown, so com-iunknown? returns #t for every interface pointers.

(com-idispatch? v)  boolean?
  v : any/c
Returns #t if v corresponds to an unsafe IDispatch, #f otherwise.

5.9.1.7 Remote COM servers (DCOM)

The optional where argument to com-create-instance can be 'remote. In that case, the server instance is run at the location given by the Registry key

HKEY_CLASSES_ROOT\AppID\CLSID\RemoteServerName

where ‹CLSID› is the CLSID of the application. This key may be set using the dcomcnfg utility. From dcomcnfg, pick the application to be run on the Applications tab, then click on the Properties button. On the Location tab, choose Run application on the following computer, and enter the machine name.

To run a COM remote server, the registry on the client machine must contain an entry at

HKEY_CLASSES_ROOT\CLSID\CLSID

where ‹CLSID› is the CLSID for the server. The server application itself need not be installed on the client machine.

There are a number of configuration issues relating to DCOM. See

http://www.distribucon.com/dcom95.html

for more information on how to setup client and server machines for DCOM.

5.9.1.8 COM Types

In the result of a function like com-method-type, symbols are used to represent various atomic types:

A type symbol wrapped in a list with 'box, such as '(box int), is a call-by-reference argument. A box supplied for the argument is updated with a new value when the method returns.

A type wrapped in a list with 'opt, such as '(opt (box int)), is an optional argument. The argument can be omitted or replaced with com-omit.

5.9.1.9 Class Display Names

The ffi/com-registry library provides a mapping from coclass names to CLSIDs for compatibility with the older MysterX interface.

A coclass name corresponds to the display name of a COM class; the display name is not uniquely mapped to a COM class, and some COM classes have no display name.

Returns a list of coclass strings for all COM classes registered on a system.

Returns a list of coclass strings for all COM classes in the system registry that have the "Control" subkey.

(coclass->clsid coclass)  clsid?
  coclass : string?
(clsid->coclass clsid)  string?
  clsid : clsid?
Converts a coclass string to/from a CLSID. This conversion is implemented by an enumeration an COM classes from the system registry.