Some additional considerations apply for Windows class libraries: Each class library must also supply a Windows LibMain function. The LibMain function is invoked automatically whenever a Windows DLL is loaded, and is responsible for identifying the library and its SOMInitModule function to the SOM Kernel. Here is an example of a typical Windows LibMain function for a SOM class library as it would appear in a C or C++ program:
#include <som.h> SOMEXTERN void SOMLINK SOMInitModule (long majorVersion, long minorVersion, string className); #include <windows.h> int CALLBACK LibMain (HINSTANCE inst, WORD ds, WORD Heapsize, LPSTR cmdLine) { SOM_IgnoreWarning (inst); SOM_ignoreWarning (ds); SOM_IgnoreWarning (heapSize); SOM_IgnoreWarning (cmdLine); SOM_ClassLibrary ("xyz.dll"); return 1; /* Indicate success to loader */ }
The only operative statement in the LibMain function is the macro SOM_ClassLibrary, which identifies the actual file name of the library as it would appear in a Windows LoadLibrary call, and internally generates a reference to the library's SOMInitModule function. This information is passed to the SOM Kernel, which in turn registers the library and schedules the execution of the SOMInitModule function.
Typically, the SOM Kernel invokes the SOMInitModule function of each statically loaded class library during execution of the SOM_MainProgram macro within the using application; otherwise, SOMInitModule is invoked immediately upon completio of the dynamic loading of a class library by an already executing application. Regardless of the loading mechanism, the SOM Kernel guarantees that the SOMInitModule function executes exactly once for each class library.