Graphical DLL

This is a discussion on Graphical DLL within the Game Programming forums, part of the General Programming Boards category; I put togrether a dll that takes a load off of drawing animations in basic API. http://queatrix.awardspace.com/index/ I'm not an ...

  1. #1
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342

    Post Graphical DLL

    I put togrether a dll that takes a load off of drawing animations in basic API.

    http://queatrix.awardspace.com/index/

    I'm not an master or expert programmer, so please, don't laugh.
    But still give me your honest opinion.

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    "structer" is spelled "structure". And the "weather"s should be "whether"s.

    You could probably add lots of constness and maybe overloaded functions.
    Code:
    BOOL index::LoadFromFile(char file_name[]);
    Loads the bitmap file_name from the hard disk into your structer.
    
    BOOL index::LoadFromResource(HINSTANCE instance, char resource_name[]);
    Loads the bitmap resource_name from instance's program into your structer.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Thanks for the reply.
    I'll fix the typos.
    What are overload functions?
    EDIT:
    Also, what do you mean by "constness"?
    Last edited by Queatrix; 09-14-2006 at 06:01 PM.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Overloaded functions are a C++ feature that allows you to have two functions with the same name but different signatures. They are not allowed in C, but I assume you don't want to retain C compatibility because you're using classes/namespaces. A function has a different signature if its parameters are different. (The return value doesn't count. If two functions have the same parameters but a different return value, they still have the same signatures.) This is valid C++:
    Code:
    void load_file(const char *fn) {}
    void load_file(string fn) {}
    void load_file(FILE *fp) {}
    void load_file(ifstream i) {}
    It makes it easier to program, because you don't have to remember so many names.

    By "constness" I meant that you should use the const keyword whenever possible. Making something const means that you won't modify it (if you try to the compiler will complain). The advantage of this is that you won't modify something you shouldn't and you can pass the function const and non-const objects. (You can't pass a const object to a function that takes a non-const parameter, because the function could potentially modify that object *1).

    Another thing you might want is default arguments. When a function has a default argument, you can leave it out when you call the function, and that function's parameter will get the defualt value.
    Code:
    void print_number(int number, char c = ' ');  /* the default value goes only in the prototype */
    
    void print_number(int number, char c) {}
    For more detailed explanations, try the tutorials or a C++ book. (Overloaded functions might be under "Polymorphism".)

    *1 You can use a const_cast to discard constness, but that's for bad designs where someone didn't make something const that they should have; you can avoid this by putting const in in the first place.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Here's a program that demonstrates polymorphism (function overloading), default arguments, and const parameters:
    Code:
    #include <iostream>
    #include <cstddef>
    
    void print_chars(char c = ' ', int number = 1); /* default parameters must be the last parameters in the function;
        you can't have a default parameter argument followed by a non-default parameter argument */
    void print_long(const char *str, int number = 1);
    
    void print_chars(char c, int number) {
        for(int x = 0; x < number; x ++) {
            std::cout << c;
        }
    }
    
    void print_long(const char *str, int number) {
        size_t len = std::strlen(str);
    
        for(int x = 0; x < len; x ++) {
            print_chars(str[x], number);
        }
    }
    
    int main(void) {
        const char *version = "1.00";  /* since print_long takes a const parameter, this variable can be passed to it */
        char greeting[] = "hello!";
    
        print_chars();  /* prints " " */
        print_chars('A');  /* prints "A" */
        print_chars('A', 3);  /* prints "AAA" */
        print_str(version);  /* prints "1.00" */
        print_str(greeting);  /* prints "hello!" */
        print_str(greeting, 3)  /* prints "hhheeelllooo!!!" */
    
        return 0;
    }
    Note: I have not compiled or testing the above program.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  6. #6
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    I think I see what you mean, you are saying I should turn:
    Code:
    BOOL index::LoadFromFile(char file_name[]);
    BOOL index::LoadFromResource(HINSTANCE instance, char resource_name[]);
    into:
    Code:
    BOOL index::LoadImage(char file_name[]);
    BOOL index::LoadImage(HINSTANCE instance, char resource_name[]);
    ???

    I will make those consts too.

    EDIT:

    Thanks for the example. (You posted it when I was posting.)
    Last edited by Queatrix; 09-14-2006 at 06:36 PM.

  7. #7
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Exactly. And you could probably provide default values for some arguments.
    Code:
    BOOL index::Animate(int play, BOOL re_play = TRUE);
    [edit] You don't need to make ordinary variables const, because the calling function won't care if the function modifies the value. But if the variable is a reference or a pointer or you're just not sure, you should probably make it const if you don't modify it. [/edit]
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  8. #8
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    And for a name;
    • queatrixGraphics
    • QGL (queatrix graphics library); already taken: http://www.google.ca/search?hl=en&q=qgl&meta=
    • QSGL (queatrix simple graphics library); posssibly taken
    • QVSGL (queatrix very simple graphics library); posssibly taken
    • Something else . . . maybe you don't want to name it yet. But at least call it "library".


    [edit] Here's a more extensive document on const: http://www.icce.rug.nl/documents/cpl...lus03.html#l35 [/edit]
    Last edited by dwks; 09-14-2006 at 08:58 PM.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  9. #9
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Quote Originally Posted by dwks
    And for a name;
    queatrixGraphics
    QGL (queatrix graphics library); already taken: http://www.google.ca/search?hl=en&q=qgl&meta=
    QSGL (queatrix simple graphics library); posssibly taken
    QVSGL (queatrix very simple graphics library); posssibly taken
    Something else . . . maybe you don't want to name it yet. But at least call it "library".
    Thanks for the advice.

    How's this? (Other than the name of course.)

    http://queatrix.awardspace.com/index/

  10. #10
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Better, although this is somewhat ambiguous:
    The following functions ALL return TRUE or FALSE depending on their success.
    [edit] And as I mentioned in a previous edit, you don't have to make non-pointer and non-reference arguments constant:
    Code:
    BOOL index::Animate(const int play, const BOOL re_play);
    If you do you still gain the advantage of the compiler reinforcing no modifications; but it can be called with a const argument either way. [/edit]
    Last edited by dwks; 09-15-2006 at 09:21 PM.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  11. #11
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    I have upgraded both the documentation and DLL it's self.
    It now has a class called indexSound.

    After comparing a simple program (with simultaneouse sounds and animations) without the DLL and with the DLL, the script size is SO much bigger. It defenitly serves it's purpose.

    >> If you do you still gain the advantage of the compiler
    >> reinforcing no modifications; but it can be
    >> called with a const argument either way.

    For some reason it wouldn't work unless I added the const to those after upgrading it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. non-MFC DLL with MFC app question.
    By Kempelen in forum Windows Programming
    Replies: 10
    Last Post: 08-20-2008, 07:11 AM
  2. Replies: 1
    Last Post: 09-18-2005, 09:06 PM
  3. dll communicating between each other
    By cloudy in forum C++ Programming
    Replies: 5
    Last Post: 06-17-2005, 02:20 AM
  4. DLL and std::string woes!
    By Magos in forum C++ Programming
    Replies: 7
    Last Post: 09-08-2004, 12:34 PM
  5. .lib vs .h vs .dll
    By Shadow12345 in forum C++ Programming
    Replies: 13
    Last Post: 01-01-2003, 04:29 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21