Introduction
There are several header files generated by the act of importing an ActiveX
control into C++ Builder. This article explains what they are, what they contain,
and what they are used for.
This material is specific to BCB4 Patch 1 and above.
The Files
The following files are generated by importing a control
-
<control>OCX.h and .cpp - These are the VCL representation of the
control itself. The class implemented by these files can be instantiated
with the normal VCL "new".
-
<control>TLB.h and .cpp - These are the classes, templates, and function
implementations / constant declaration / definitions for the classes specified
in the control type library. These are not able to be instantiated using
the VCL "new", as discussed later in this document.
The OCX File
This is a fairly simple file for those used to reading VCL header files. The
control class definition is present. This definition contains VCL representations
of the control properties, methods, and events. VCL style classes to support
the various subobjects are not generated - unfortunately, this is as deep as
VCL support for the control goes. If you need to use subobjects of this class,
you will generally have to use the classes declared in the TLB files. In most
cases, this will be similar to working with VCL objects - until you need to
create one from scratch, as discussed later.
The TLB File
This is a much more complex file. For a reasonably sized control, it can be
nearly 10,000 lines. The size of these files for large applications like Excel
is truly legendary.
The following are the contents of this file
- class GUID, DIID etc constants; here declared as extern and initialized
in the TLB .cpp; NOTE: If you use the control in a package, you must change
each extern const GUID declaration in the .h to extern __declspec (package)
const GUID, or else the declarations will not be visible in using applications
or packages.
For each class in the TLB...
-
The "class" declaration; this is an interface and is an abstract
class. It cannot be instantiated.
-
The typedefed pointer to "class" ("class"Ptr).... a
smart-interface wrapper. Initialized by a call to the creator class (see
CoClass below), or a method on an existing interface that returns one.
-
"class"DispT<> a template class which is the non-abstract
version of the IDispatch interface to the "class". It is used
to call Invoke on the underlying interface and to hide that aspect of interacting
with the interface.
-
"class"Disp a typedef to conceal the "templateness"
of the DispT class.
-
TCoClassCreatorT<"class"Disp, "class", &CLSID_"classwithoutprefix", &DIID_"class"Co"classwithoutprefix">
used to set up new instances of the specified class. This is done with the
Create method.
Conclusion
Though complex, the files generated for an imported control can be more easily
used when they are understood. This article outlines thei contents and function
of these files.
|
|