SilverScreen Solid Modeler

Creating a SilverPlus Stub

Creating a SilverPlus Stub

Previous topic Next topic  

Creating a SilverPlus Stub

Previous topic Next topic JavaScript is required for the print function  

SilverPlusEllipse

 

Creating a SilverPlus Stub

 


A SilverPlus stub is a SilverC program that manages the loading and unloading of a SilverPlus DLL. The SilverC program that loads a SilverPlus DLL is not special or restricted in any way. However, experience has taught that a SilverPlus DLL should perform the SilverPlus application's work, and that the SilverC program should do little more than invoke the application. The term 'stub' was born of this minimalist approach to the task.

 

 


Assuming that you have created a SilverPlus DLL called SilverDLL, and that you wish to write a SilverC stub to load it, make it work, and then unload it, here is how you would proceed:

 

The following code is SilverC code to load the DLL developed earlier in this chapter. It is assumed to reside in either a Debug or Release sub-diretory of SilverScreen, depending upon how it was built.

 

C Code

 

 #include "silver.h"

 #include "stdio.h"

 #include "rexcodes.h"

 

 

 void main( void )

    {

    int        hDLL;

    char       DLL_Path[_MAX_PATH];

    SS_VERSION ver;

    int        answer;

 

 

    // Get version information from SilverScreen

 

    get_version(&ver);

 

 

    // Construct a path to the DLL

 

    path_silver(DLL_Path);

 

    if ( ver.is_debug )

       strcat(DLL_Path, "Debug\\SilverDLL.dll");

    else

       strcat(DLL_Path, "Release\\SilverDLL.dll");

 

 

    // Load the SilverPlus DLL

 

    if ( ! (hDLL = rex_load( DLL_Path )) )

       {

       error_message("rex_load \"%s\" failed.\nError code: %d",

                     DLL_Path,

                     ss_errno);

       return;

       }

 

    // Instruct the DLL to perform work via the user-defined code

 

    answer = rex_exec(hDLL, REX_USER_BASE, 0);

 

    if ( answer != 0 )

       panel_message("SilverPlus is fun");

    else

       panel_message("SilverPlus is not fun");

 

 

    // Unload the DLL and return to SilverScreen

 

    rex_unload( hDLL );

    }

 

 

 


A line in the above code has been marked in red to draw your attention to it. The SilverPlus entry point you wrote earlier returned a value of 1 if the user answered yes and 0 otherwise. That value is returned through the rex_exec function to your SilverC stub. In this way you may communicate between the stub and the DLL.

 

 

 

See Also: SilverC Language Development