Customizing DLL loading
To dynamically load a SOM class, the SOMClassMgrObject calls the
function pointed to by the global variable SOMLoadModule to load
the DLL containing the class. The reason for making public the SOMLoadModule
function (and the following SOMDeleteModule function) is to reveal
the boundary where SOM touches the operating system. Explicit invocation
of these functions is never required. However, they are provided to allow
class implementors to insert their own code between the operating system
and SOM, if desired. The SOMLoadModule function has the following
signature:
long (*SOMLoadModule)
( string className,
string fileName,
string functionName,
long majorVersion,
long minorVersion,
somToken *modHandle);
This function is responsible for loading the DLL containing the SOM
class className and returning either the value zero (for success)
or a nonzero system-specific error code. The output argument modHandle
is used to return a token that can subsequently be used by the DLL-un
loading routine (described below) to unload the DLL. The default DLL-loading
routine returns the DLL's module handle in this argument. The remaining
arguments are used as follows:
Argument
fileName
The file name of the DLL to be loaded, which
can be either a simple name or a full path name.
functionName
The name of the routine to be called after
the DLL is successfully loaded by the SOMClassMgrObject. This routine
is responsible for creating the class objects for the class(es) contained
in the DLL. Typically, this argument has the value "SOMInitModule",
which is obtained from the function SOMClassInitFuncName described
above. If no SOMInitModule entry exists in the DLL, the default DLL-loading
routine looks in the DLL for a procedure with the name <className>NewClass
instead. If neither entry point can be found, the default DLL-loading
routine fails.
majorVersion
The
major version number to be passed to the class initialization function in
the DLL (specified by the functionName argument).
minorVersion
The minor version number to be passed to the
class initialization function in the DLL (specified by the FunctionName
argument).
An application program can replace the default DLL-loading routine by assigning
the entry point address of the new DLL-loading function (such as MyLoadModule)
to the global variable SOMLoadModule, as follows:
#include <som.h>/* Define a replacement routine: */
long myLoadModule (string className, string fileName,
string functionName, long majorVersion,
long minorVersion, somToken *modHandle)
{
(Customized code goes here)
}
...
SOMLoadModule = MyLoadModule;
[Back: Customizing class initialization]
[Next: Customizing DLL unloading]