COM Objects and the Dyalog APL DLL
Introduction
Each different implementation of Dyalog contains two versions of the Dyalog APL Dynamic Link Library, a development version (Development DLL) and a run-time version (Run-Time DLL). For further details, see Files.
In the remainder of this section, the term Dyalog APL DLL is used to refer to any one of these DLLs. The term COM object is used to refer to a Dyalog APL in-process OLE Server (OLEServer object) or a Dyalog APL ActiveX Control (ActiveXControl object).
The Dyalog APL DLL is used to host COM objects and .NET objects written in Dyalog APL. Although this section describes how it operates with COM objects, much of this also applies when it hosts .NET objects. Further information is provided in the .NET Interface Guide.
Classes, Instances and Namespace Cloning
A COM object, whether written in Dyalog APL or not, represents a class. When a host application loads a COM object, it actually creates an instance of that class.
When a host application creates an instance of a Dyalog APL COM object, the corresponding OLEServer or ActiveXControl namespace is cloned. If the host creates a second instance, the original namespace is cloned a second time.
Cloned OLEServer and ActiveXControl namespaces are created in almost exactly the same way as those that you can make yourself using ⎕OR
and ⎕WC
except that they do not have separate names. In fact, each clone believes itself to be the one and only original OLEServer or ActiveXControl namespace, with the same name, and is completely unaware of the existence of other clones.
Notice that cloning does not initially replicate all the objects within the OLEServer or ActiveXControl namespace. Instead, the objects inside the cloned namespaces are actually represented by pointers to the original objects in the original namespace. Only when an object is changed does any information get replicated. Typically, the only objects likely to differ from one instance to another are variables, so only one copy of the functions will exist in the workspace. This design enables many instances of a Dyalog APL COM object to exist without overloading the workspace.
Workspace Management
By default, the Dyalog APL DLL does not use a fixed maximum workspace size, but automatically increases the size of its active workspace as required. If you write a run-away COM object, or if there is insufficient computer memory available to load a new control, it is left to the host application or to Windows itself to deal with the situation.
Nevertheless, it is possible to specify a value for maxws for the application in which the Dyalog APL DLL is embedded. This is achieved by defining a Registry key named:
HKLM\Software\Dyalog\Embedded\<appname>
or on 64-bit Windows:
HKLM\Software\Wow6432Node\Dyalog\Embedded\<appname>
where <appname>
is the name of the application, containing a String Value named maxws
set to the desired size. If you were running an APL in-process server from Microsoft Excel, the application name would be excel.exe
.
When an application loads its first Dyalog APL COM object, it starts the Dyalog APL DLL which initialises a CLEAR WS
. It then copies the namespace tree for the appropriate OLEServer or ActiveXControl object into its active workspace.
This namespace tree comprises the OLEServer or ActiveXControl namespace itself, together with all its parent namespaces with the exception of the root workspace itself. Note that for an ActiveXControl, there is at least one parent namespace that represents a Form.
For example, if an ActiveXControl namespace is called #.F.Dual
, the Dyalog APL DLL will copy the contents of #.F
into its active workspace when the first instance of the control is loaded by the host application.
If the same host application creates a second instance of the same OLEServer or ActiveXControl, the original namespace is cloned as described above and there is no further impact on the workspace
If the same host application creates an instance of a different Dyalog APL COM object, the namespace tree for this second object is copied from its DLL or OCX file into the active workspace. For example, if the second control was named X.Y.MyControl
, the entire namespace X
would be copied.
This design raises a number of points:
- Unless you are in total control of the user environment, you should design a Dyalog APL COM object so that it can operate in the same workspace as another Dyalog APL COM object supplied by another author. You cannot make any assumptions about file ties or other resources that are properties of the workspace itself.
- If you write an ActiveXControl whose ultimate parent namespace is called
F
, a host application could not use your control at the same time as another ActiveXControl (perhaps supplied by a different author) whose ultimate parent namespace is also calledF
. - Dyalog APL COM objects must not rely on variables or utility functions that were present in the root workspace when they were saved. These functions and variables will not be there when the object is run by the Dyalog APL DLL.
- A Dyalog APL COM object may create and subsequently use functions and variables in the root workspace, but if two different COM objects were to adopt the same policy, there is a danger that they would interfere with one another. The same is true for
⎕SE
.
Multiple COM Objects in a Single Workspace
If your workspace contains several OLEServer or ActiveXControl objects which have the same ultimate parent namespace, the Dyalog APL DLL will copy them all into the active workspace at the time when the first one is instanced. If the host application requests a second COM object that is already in the workspace, the namespace tree is not copied again.
If the workspace contains several OLEServer or ActiveXControl objects which have different ultimate parents, their namespace trees will be copied in separately.
Parameters
With the exception of maxws (see above) the Dyalog APL DLL does not read parameters from the registry, command-line or environment variables. This means that all such parameters will have their default values.