Thread: Should I consider including my .DLL source code in my program?

  1. #1
    Registered User HelpfulPerson's Avatar
    Join Date
    Jun 2013
    Location
    Over the rainbow
    Posts
    288

    Should I consider including my .DLL source code in my program?

    I have a DLL written in C which I link dynamically by executing the following line of functions.

    Code:
    /* Preprocessor directives */
    
    
    /* Prepare for C-style declarations */
    #ifdef __cplusplus
    extern "C"
    {
    #endif // _cplusplus
    
    
    #include "game.h"
    #include <stdio.h>
    #include <stdlib.h>
    
    
    #ifdef __cplusplus
    };
    #endif // __cplusplus
    
    
    t_wait wait;
    ft_timer timer;
    
    
    t_SDL_errorexit SDL_errorexit;
    
    
    t_load_texture load_texture;
    
    
    t_load_music load_music;
    t_play_music play_music;
    t_start_music start_music;
    
    
    t_load_sound load_sound;
    t_play_sound play_sound;
    
    
    t_character_to_digit character_to_digit;
    t_number_of_value_places number_of_value_places;
    t_convert_number_to_string convert_number_to_string;
    
    
    t_create create;
    t_print_list print_list;
    t_free_list free_list;
    t_add add;
    t_delete_node delete_node;
    
    
    t_free_level_list free_level_list;
    t_print_level_list print_level_list;
    t_delete_level delete_level;
    
    
    t_loadfile_RW loadfile_RW;
    t_read_file read_file;
    t_load_level_data load_level_data;
    
    
    /* ******************************************************** */
    /* *********       win_error( char *, bool )      ********* */
    /* ******************************************************** */
    /*  - Displays a GUI for a windows specific error message,  */
    /* pass true to it to have it exit the program, pass false  */
    /* to have it continue                                      */
    /* ******************************************************** */
    
    
    extern void win_error( char * message, bool is_exit )
    {
        /* Note : win_error uses the Win32 Api */
        /* ********************************** */
    
    
        char buffer[BUFSIZ] = { 0 }; /*     This is the buffer where the error message is stored from the FormatMessage( )
                                        function.
                                     */
        DWORD error_code = GetLastError( ); /* GetLastError( ) returns the last system error code */
    
    
        /* Formats an error message from the system */
        FormatMessage
        (
            FORMAT_MESSAGE_FROM_SYSTEM,
            NULL,
            error_code,
            MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ),
            ( LPTSTR ) buffer,
            BUFSIZ,
            NULL
        );
    
    
        MessageBox( NULL, buffer, message, MB_ICONWARNING | MB_OK ); /* Shows the user a message box with the message */
    
    
        if ( is_exit ) exit( error_code );
    
    
        return;
    }
    
    
    /* ******************************************************** */
    /* *********   dll_functions_init( game_data * )  ********* */
    /* ******************************************************** */
    /*  - Imports any functions we need to use from our DLL     */
    /* ******************************************************** */
    
    
    static void dll_functions_init( game_data * game )
    {
        /* Note : DLL_functions_init uses the Win32 Api */
        /* ******************************************** */
    
    
        /* Load the DLL dynamically */
        if ( !( game->game_dll = LoadLibrary( "game_lib_dynamic.dll" ) ) )
            win_error( ( char * )"Loading DLL", true );
    
    
        /* Get the addresses of our functions for use in the game */
        if ( !( wait = ( t_wait )GetProcAddress( game->game_dll, "wait" ) ) )
            win_error( ( char * )"wait( )", true );
        if ( !( timer = ( ft_timer )GetProcAddress( game->game_dll, "timer" ) ) )
            win_error( ( char * )"timer( )", true );
    
    
        if ( !( SDL_errorexit = ( t_SDL_errorexit )GetProcAddress( game->game_dll, "SDL_errorexit" ) ) )
            win_error( ( char * )"SDL_errorexit( )", true );
    
    
        if ( !( load_texture = ( t_load_texture )GetProcAddress( game->game_dll, "load_texture" ) ) )
            win_error( ( char * )"load_texture( )", true );
    
    
        if ( !( load_music = ( t_load_music )GetProcAddress( game->game_dll, "load_music" ) ) )
        {
            win_error( ( char * )"load_music( ) ( warning : no music will be played )", false );
            game->sound_data.invalid_music_functions = true;
        }
        if ( !( play_music = ( t_play_music )GetProcAddress( game->game_dll, "play_music" ) ) )
        {
            win_error( ( char * )"play_image( ) ( warning : no music will be played )", false );
            game->sound_data.invalid_music_functions = true;
        }
        if ( !( start_music = ( t_start_music )GetProcAddress( game->game_dll, "start_music" ) ) )
        {
            win_error( ( char * )"start_music( ) ( warning : no music will be played )", true );
            game->sound_data.invalid_music_functions = true;
        }
    
    
        if ( !( load_sound = ( t_load_sound )GetProcAddress( game->game_dll, "load_sound" ) ) )
        {
            win_error( ( char * )"load_sound( ) ( warning : no sounds will be played )", false );
            game->sound_data.invalid_sound_functions = true;
        }
        if ( !( play_sound = ( t_play_sound )GetProcAddress( game->game_dll, "play_sound" ) ) )
        {
            win_error( ( char * )"play_sound( ) ( warning : no sounds will be played )", true );
            game->sound_data.invalid_sound_functions = true;
        }
    
    
        if ( !( character_to_digit = ( t_character_to_digit )GetProcAddress( game->game_dll, "character_to_digit" ) ) )
            win_error( ( char * )"character_to_digit( )", true );
        if ( !( number_of_value_places = ( t_number_of_value_places )GetProcAddress( game->game_dll, "number_of_value_places" ) ) )
            win_error( ( char * )"number_of_value_places( )", true );
        if ( !( convert_number_to_string = ( t_convert_number_to_string )GetProcAddress( game->game_dll, "convert_number_to_string" ) ) )
            win_error( ( char * )"convert_number_to_string( )", true );
    
    
        if ( !( create = ( t_create )GetProcAddress( game->game_dll, "create" ) ) )
            win_error( ( char * )"create( )", false );
        if ( !( print_list = ( t_print_list )GetProcAddress( game->game_dll, "print_list" ) ) )
            win_error( ( char * )"print_list( )", false );
        if ( !( free_list = ( t_free_list )GetProcAddress( game->game_dll, "free_list" ) ) )
            win_error( ( char * )"free_list( )", false );
        if ( !( add = ( t_add )GetProcAddress( game->game_dll, "add" ) ) )
            win_error( ( char * )"add( )", false );
        if ( !( delete_node = ( t_delete_node )GetProcAddress( game->game_dll, "delete_node" ) ) )
            win_error( ( char * )"delete_node( )", false );
    
    
        if ( !( free_level_list = ( t_free_level_list )GetProcAddress( game->game_dll, "free_level_list" ) ) )
            win_error( ( char * )"free_level_list( )", true );
        if ( !( print_level_list = ( t_print_level_list )GetProcAddress( game->game_dll, "print_level_list" ) ) )
            win_error( ( char * )"print_level_list( )", true );
        if ( !( delete_level = ( t_delete_level )GetProcAddress( game->game_dll, "delete_level" ) ) )
            win_error( ( char * )"delete_level( )", true );
    
    
        if ( !( loadfile_RW = ( t_loadfile_RW )GetProcAddress( game->game_dll, "loadfile_RW" ) ) )
            win_error( ( char * )"loadfile_RW( )", true );
        if ( !( read_file = ( t_read_file )GetProcAddress( game->game_dll, "read_file" ) ) )
            win_error( ( char * )"read_file( )", true );
        if ( !( load_level_data = ( t_load_level_data )GetProcAddress( game->game_dll, "load_level_data" ) ) )
            win_error( ( char * )"load_level_data( )", true );
    
    
        return;
    }
    Which loads the functions and the libraries fine, but I am considering whether I should do this, or just include the source code in the project. I have access to all of the source code in that particular DLL since I created it, but I don't really have access to SDL's source code. What I was considering doing was to take the source code and reorganize it into separate files in my current project and then download the Mac/Linux libraries for SDL and using preprocessor directives and some tricks to link them correctly. It would still take quite a while, and the project deadline for the competition is January 16. The competition requirement is only that it works on Windows XP, which it currently does, but I was considering adding multi-platforming if I had the extra time. My question is, is it really worth it? I don't think much of the possible users will be using different OSes, but I can't be sure of that.
    "Some people think they can outsmart me, maybe. Maybe. I've yet to meet one that can outsmart bullet" - Meet the Heavy, Team Fortress 2

  2. #2
    Registered User
    Join Date
    Nov 2012
    Posts
    1,393
    Quote Originally Posted by HelpfulPerson View Post
    What I was considering doing was to take the source code and reorganize it into separate files in my current project and then download the Mac/Linux libraries for SDL and using preprocessor directives and some tricks to link them correctly. It would still take quite a while, and the project deadline for the competition is January 16. The competition requirement is only that it works on Windows XP, which it currently does, but I was considering adding multi-platforming if I had the extra time. My question is, is it really worth it?
    No. The answer is already underlined in your quote.

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    3,673
    I would suggest redoing the library as a static library if you get no other feedback.
    This keeps it in a Library in case you decide to go back to a DLL in the future.

    If you never plan to reuse the code then it makes no sense to have it in a library be it DLL or Static.

    The reason to use a DLL is ease of doing installation and binary upgrade.

    If you have no plans to ever do binary upgrades or write a second program using the same library then no reason to make it a DLL.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to make a program that prints it's own source code???
    By chottachatri in forum C++ Programming
    Replies: 38
    Last Post: 03-28-2008, 07:06 PM
  2. Paint Program Example Source Code??
    By Welder in forum Windows Programming
    Replies: 9
    Last Post: 11-08-2007, 06:23 PM
  3. How Can I compile 3 source code in 1 program ?
    By lord_cedrich in forum C Programming
    Replies: 8
    Last Post: 12-10-2006, 05:10 AM
  4. My first program source code
    By Musicdip in forum C++ Programming
    Replies: 5
    Last Post: 09-28-2002, 11:55 PM