This package allows R users to explore type information coming from
either type libraries or COM objects. The functions provide
information about a class in terms of its properties; methods and
their argument and return types; the names and values of enumerated
types, and fields in structures and unions.
One can find type information by loading a type library or by
obtaining a reference to a COM object. Suppose we have the ADO
(ActiveX Data Object) library on our system at it is located at
C:/Program Files/Common Files/system/ado/msado15.dll.
We load that library using
LoadTypeLib
lib = LoadTypeLib("C:/Program Files/Common Files/system/ado/msado15.dll")
|
---|
The resulting
lib is a reference or handle to the
C-level structure that identifies the object. We can use this to
examine the different elements about which the library provides type
information. When we are finished with it, we can release the library
and free the resources it uses using
UnloadTypeLib. (Not
implemented yet.)
Essentially we can treat the type library as a named list.
Each element is an object of type ITypeInfo in our
world. This provides a reference to the elemenet in the type library
and from that we can find out most things about that type.
Since the library reference is equivalent to a list
in S, we can find out the names
of the different elements it contains.
As one might expect, we can extract elements from the type
library in the S style using either
lib[[1]]
lib[1:4]
lib[["CursorTypeEnum"]]
lib[[names(lib)[1]]]
lib$CursorTypeEnum
|
---|
Now that we know how to navigate the type library,
we can examine its elements.
We can also find out the types of these different elements
using \SFunction{getTypeLibTypes}.
This describes the type of each element in the library by its type
name such as dispatch, coclass, enum. These are indexed by the names
of the type. If one wants to get the actual numeric type rather than
the text descriptions (so that they can be used within the C code),
use the
byName argument and specify
FALSE.
We can ``zoom in'' and look at the type information for individual
elements of the type library. We get a reference to the underlying C
<c:struct>ITypeInfo</c:struct> object using the overloaded
[[. One
can index the type library reference either by the name or position of
the desired element.
or
We can then get the details of the type of this element using this
object. For example, we can find the collection of values in the
enumeration
BookMarkEnum.
Suppose we wanted to find all the enumerations
within a library and obtain their definitions
as a name-value vector for each enum type.
We can do this in two steps
types = getTypeLibTypes(lib)
enums = which(types == "enum")
lapply(enums, function(x) getEnum(lib[[x]]))
|
---|
getVars(lib[["FieldEnum"]])
|
---|
If an element in the type library is a coclass type info object, then
it can represent multiple interfaces. We get a list of the
ITypeInfo objects for each of these interfaces by
calling
getElements. We can the operate on each of
these
ITypeInfo elements as we do above. The
getElements function has a
recursive
argument
See
http://archive.devx.com/upload/free/features/vcdj/2000/03mar00/fg0300/fg0300.asp
for an article describing aspects of type libraries.