SilverScreen Solid Modeler

DLL Loading Review

DLL Loading Review

Previous topic Next topic  

DLL Loading Review

Previous topic Next topic JavaScript is required for the print function  

SilverPlusEllipse

 

DLL Loading Review

 


Here is a review of the process to load a SilverPlus DLL.

 

A SilverPlus DLL is loaded from a SilverC program called a stub. The stub loads the SilverPlus DLL via the SilverScreen API routine rex_load.

 

rex_load loads the SilverPlus DLL via the Win32 function LoadLibrary.

 

If the DLL is found, LoadLibrary attempts to load it, and in doing so, calls the DLL entry point (DllMain in our case). In addition, if it is a C++ DLL, then all global objects are initialized (i.e., the constructors of global objects are invoked, including that of the CWinApp derived main class).

 

At this point the SilverPlus entry point (the SilverCExec function) has not been called, so you may not call SilverScreen API functions (i.e., not in the DLL_PROCESS_ATTACH section of DllMain, or in the constructor for your CWinApp derived class).

 

If the library is successfully loaded,  then SilverScreen attempts to locate the SilverCExec (or _SilverCExec) function in the SilverPlus DLL (by using GetProcAddress). If neither SilverCExec nor _SilverCExec is found, then the load fails, and rex_load returns 0. Otherwise, SilverScreen calls SilverCExec with an op value of REX_FIRST_LOAD. At this point, the SSREX pointer will be passed as well, and the DLL should store this pointer in a variable so that the DLL can call SilverScreen API functions.

 

Following this, SilverScreen calls SilverCExec with a value of REX_LOADING. rex_load then returns a handle which should then be used in subsequent calls to rex_exec and rex_unload.